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

Delaying os.shutdown()

Started by Bahooki, 09 August 2012 - 03:35 AM
Bahooki #1
Posted 09 August 2012 - 05:35 AM
Hi, I'm trying to make a menu, and when you select something I want it to say a certain piece of text then shutdown, which is what I'm have trouble with. So basically, I need to know how to delay os.shutdown().
I quick example is:

while x ~= "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49\n")
os.shutdown()
-- I need the shutdown delayed
Pharap #2
Posted 09 August 2012 - 05:55 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
Bahooki #3
Posted 09 August 2012 - 05:56 AM
I want it to shut down.
Bahooki #4
Posted 09 August 2012 - 06:11 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.
Pharap #5
Posted 09 August 2012 - 06:23 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
Bahooki #6
Posted 09 August 2012 - 06:28 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.
D3matt #7
Posted 09 August 2012 - 06:42 AM
sleep(number)
os.shutdown()
Pharap #8
Posted 09 August 2012 - 06:42 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Bahooki #9
Posted 09 August 2012 - 07:00 AM
Thanks
Bahooki #10
Posted 09 August 2012 - 08:08 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
Pharap #11
Posted 09 August 2012 - 08:12 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
sleep(5)
os.shutdown()
end
end
Bahooki #12
Posted 09 August 2012 - 09:00 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
I noticed you changed the code a tad bit, is that part needed? or is that just a preference?
sleep(5)
os.shutdown()
end
end
Bahooki #13
Posted 09 August 2012 - 09:02 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
I noticed you changed the code a tad bit, is that part needed? or is that just a preference?
sleep(5)
os.shutdown()
end
end
fail. I noticed you changed the code a bit, is that needed to make it work, or is it just preference?
Pharap #14
Posted 09 August 2012 - 09:37 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
I noticed you changed the code a tad bit, is that part needed? or is that just a preference?
sleep(5)
os.shutdown()
end
end
fail. I noticed you changed the code a bit, is that needed to make it work, or is it just preference?
Well if you're going to be rude about it, I'm not going to help you.
Cloudy #15
Posted 09 August 2012 - 09:42 AM
I believe he was saying fail because he did it wrong, not because of you.

And please actually put your message when quoting - if you do it wrong, edit your message into it rather than posting again.
Bahooki #16
Posted 09 August 2012 - 09:49 AM
Well, it depends how long you want to delay it for.
sleep(number)
will sleep the computer for that number of seconds, then carry on to the next line. During the sleep command, the computer cannot process any other commands.

Or, if you want to do other stuff before shutting down, you can use a timer and make the system shut down when the timer goes off. Which is more suiting to what you require?
I want it to shutdown.

Yes, I got that bit, but are you planning to do anything else during the delay or do you not mind the computer being useless during the delay before it shuts down?
I don't mind it being useless before the shutdown.

Then just put sleep(5) before os.shutdown() and it will pause for 5 seconds before shutting down. If you want a longer/shorter time, replace the 5 with another number.
Just got around to trying it, no luck. I get a ) expected error. Is it supposed to be just: sleep(5)os.shutdown()? That's what I've been trying. Or is it like os.shutdown(sleep5)?
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
I noticed you changed the code a tad bit, is that part needed? or is that just a preference?
sleep(5)
os.shutdown()
end
end
fail. I noticed you changed the code a bit, is that needed to make it work, or is it just preference?
Well if you're going to be rude about it, I'm not going to help you.
Sorry for a misunderstanding, I said fail because I had put my response in my code.
Pharap #17
Posted 09 August 2012 - 10:19 AM
I believe he was saying fail because he did it wrong, not because of you.

And please actually put your message when quoting - if you do it wrong, edit your message into it rather than posting again.

Was the 2nd comment for me or him?
Cloudy #18
Posted 09 August 2012 - 10:23 AM
I believe he was saying fail because he did it wrong, not because of you.

And please actually put your message when quoting - if you do it wrong, edit your message into it rather than posting again.

Was the 2nd comment for me or him?

Him - sorry for confusion
Pharap #19
Posted 09 August 2012 - 10:26 AM
They are supposed to be on separate lines eg:


x = " "
while not x == "Exit" do
print("Type Derp to find how much a cheeseburger is")
x = io.read()
if x == "Derp" then
print("$1.49")
I noticed you changed the code a tad bit, is that part needed? or is that just a preference?
sleep(5)
os.shutdown()
end
end
fail. I noticed you changed the code a bit, is that needed to make it work, or is it just preference?
Well if you're going to be rude about it, I'm not going to help you.
Sorry for a misunderstanding, I said fail because I had put my response in my code.
Right, Ok then. Guessing English isn't your first language (hence it helps to at least say what your native language is, since some people here speak other languages).
And yes, it is needed. For every while do, for do and if then there has to be an end.
Also the sleep has to come before the shutdown.
Every line of code is an instruction, and a computer reads it line by line.
Pharap #20
Posted 09 August 2012 - 10:27 AM
I believe he was saying fail because he did it wrong, not because of you.

And please actually put your message when quoting - if you do it wrong, edit your message into it rather than posting again.

Was the 2nd comment for me or him?

Him - sorry for confusion
It's fine, I thought it was, but things tend to get confusing around the forums, particularly where new users are concerned.