This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LUIGI5MASH's profile picture

Sleep(Time)

Started by LUIGI5MASH, 12 October 2014 - 03:36 AM
LUIGI5MASH #1
Posted 12 October 2014 - 05:36 AM
I want my program ask me how long my door should stay open for. I thought i might be able to use a variable but it doesn't work
Lyqyd #2
Posted 12 October 2014 - 05:38 AM
Please post your code.
LUIGI5MASH #3
Posted 12 October 2014 - 05:40 AM
Kinda of a noob how do i do that?

How do i do that?

How do i do that?

How do i do that?

How do i do that?

How do i do that?

Im a noob but how do i do that?

How?

Im a noob but how do i do that?

How?
ElvishJerricco #4
Posted 12 October 2014 - 06:15 AM
So obviously we'd like to see your code. But I can make a guess at what you might be trying to do.


time = read()
sleep(time)

The issue here is that time is the string for what they typed. The sleep function takes a number. Is this your issue? If so you just need to wrap read in a tonumber call.


time = tonumber(read())
sleep(time)

tonumber will return nil if what they typed isn't a valid number, so check for that.
TheOddByte #5
Posted 12 October 2014 - 05:21 PM
That kinda looks like spam o.o

Anyway, this is an example on how you can do ( probably ) what you want

write( "Sleep for how long? " )
local input = tonumer( read() ) -- convert input into a number
sleep( input ) -- sleep for the time inputted
Edited on 12 October 2014 - 03:21 PM
Lyqyd #6
Posted 12 October 2014 - 07:46 PM
That kinda looks like spam o.o

That's what happens when New Members post essentially the same thing ten times in a row because they haven't read the Forum Guidelines or the notice that helpfully displays when you post that your posts have to be approved before they become visible and I come by and squish all ten of them into one post before approving it.
Bomb Bloke #7
Posted 13 October 2014 - 12:14 AM
Ah. I thought he was quoting a musical number.