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

Question

So I built a drone, and finally managed to get a custom bios running for test purposes. The problem is that I can't seem to get it to sleep (so that a move command can finish). Each time I try, I get the following error:

bios:6: attempt to call field 'sleep' (a nil value)

The code I'm using is:

--local os = require("os")
local drone = component.proxy(component.list("drone")())
while true do
  drone.move(1,1,1)
  --print("zomgwtf")
  os.sleep(1)
  drone.move(-1,-1,-1)
end
 

(The print and require statements were leftovers of various debugging attempts.)

 

There's got to be a way to sleep right? Drones are going to need to wait sometimes, but there doesn't seem to be any function to do that. I know the sleep command works, since os.sleep works on a computer when placed in a script, and thus there's no live lua interpreter magic going on when calling sleep. What's up here?

 

Edit: Version info:

Minecraft 1.7.10

Forge: 10.13.2.1240

OpenComputers:1.5.8.17

Edited by AliceTheGorgon
Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Yeah, sorry about that. I apparently managed to miss the little popup the first time I tried posting. I suppose that's what I get for trying to use the internet so late at night.

 

In more useful news, I edited the first post with the version info, which I really should have added to begin with. Hopefully my drone issue is not also such a stupid mistake on my part.

Link to post
Share on other sites
  • 0

The only thing I can suggest at the moment is to extend your sleep time, it's not exactly accurate and short sleep times maybe missed, try increasing it to 10 or something longer than 3 at any rate and see if it works then.

os.sleep(1) works fine on computers and robots though. It's just on drones (and probably microcontrollers) that it crashes.

 

I suspect that microcontrollers are missing a lot of the base functionality in computers, since none of the os.* functions seem to work. This makes sense for the most part, though there ought to be some analogue to "sleep", even if it's just manually running a loop that does nothing for a while.

For my specific use case, I might be able to loop until getVelocity() equals 0, which I did forget to check, but there's probably a more general way to do it that I'm simply unaware of.

 

One thing's for sure though, as soon as I get this solved I'm going to start writing up some tutorials on the wiki.

 

Edit: Spelling.

Edited by AliceTheGorgon
Link to post
Share on other sites
  • 0
  • Solution

You're in the BIOS- there is no sleep function. You've clearly already figured out that you can't just require() the os module, because that's provided by OpenOS, which you don't have here.

 

The OpenOS implementation of os.sleep is here. Notice that it just polls events until it reaches the timeout. You could do that yourself, but now you have to figure out what you're going to do with all the events you get, since there doesn't seem to be a way to pause execution with computer.pullSignal without actually receiving events.

Link to post
Share on other sites
  • 0

Awesomeness. Thanks for that. In the future I'll have to remember to check to OS for thing like this. I'm still stuck in "other mod" mode I guess, where everything is a mod builtin function.

 

I do find it amusing though, that the sleep function for regular computers is literally just attempting to pull events for however long, which is just the kind of hackish workaround I had been wondering about for the drones.  :lol:

Link to post
Share on other sites
  • 0

Fun fact: "The other mod" also uses an event loop. But it is waiting for a special timer event instead of actively checking the time.

(Yes, you can also read all CC lua source files if you open it's Jar file. But searching OCs files in github is far easier. ;) )

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.