Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
CapitalHitman38

check available space

Question

Hey all, i'm a huge newbie at this and all of my lua programming  knowledge is from computercraft, and very little knowledge at that. I am messing around with OC and am trying to make a program that displays the used space of the hard drive(s) that the computer(server in this case) is connected to for learning purposes, what i typed was.

 

space = spaceUsed():number

print ("Your used space in bytes is:", space)

 

and it gives me

 

/usedspace:2: function argument expected near 'print'

 

when i try to run it. Im not sure if what im doing wrong, or even if that is valid lua.

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

 

 

space = spaceUsed():number

 

Oh, I see what you did. You copied from the documentation. Generally in documentation it's standard to put the type of variable that a function returns after a colon. All you need is the part before :number. That part just tells you that that method returns a number.

Link to post
Share on other sites
  • 0

Oh, I see what you did. You copied from the documentation. Generally in documentation it's standard to put the type of variable that a function returns after a colon. All you need is the part before :number. That part just tells you that that method returns a number.

So i dont need to put in ":number" because that is just telling me what type of variable its going to output?

 

I did that and now it says

 

/usedspace:1: attempt to call a nil value (global 'spaceUsed')

stack traceback:

             /usedspace:1: in main chunk

              (...tailcalls...)

Link to post
Share on other sites
  • 0

You're missing the require for the filesystem component. Also, the name of the variable used to require the filesystem component in needs to be placed in front of the spaceUsed() method. In total, it should look like this:
 

local component = require("component")
fs = component.filesystem
space = fs.spaceUsed()
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.