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

Cafe [Lua][Help]

Started by Drsirdeath, 24 July 2012 - 01:33 PM
Drsirdeath #1
Posted 24 July 2012 - 03:33 PM
I'm having trouble with a program. And I can't figure it out. Help?
heres the program:

print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:") then
if input = "C" then
rs.setOuput("top", true)
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleeep(1)
os.reboot()
else
if input = "P" then
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
if input = "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
else
print("Sorry that is not a valid order!")
os.reboot()

When i submit this it says:
bios:206: [string "startup"]:8: unexpected symbol
But i can't find whats wrong. Although im sure theres more then one thing wrong in here.
Can i get some help please?
Kolpa #2
Posted 24 July 2012 - 04:15 PM
I'm having trouble with a program. And I can't figure it out. Help?
heres the program:

print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:") then
if input = "C" then
rs.setOuput("top", true)
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleeep(1)
os.reboot()
else
if input = "P" then
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
if input = "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
else
print("Sorry that is not a valid order!")
os.reboot()

When i submit this it says:
bios:206: [string "startup"]:8: unexpected symbol
But i can't find whats wrong. Although im sure theres more then one thing wrong in here.
Can i get some help please?
1. Please use CODE tags :)/>/>

print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:") then
if input = "C" then
rs.setOuput("top", true)
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleeep(1)
os.reboot()
else
if input = "P" then
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
if input = "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
else
print("Sorry that is not a valid order!")
os.reboot()
2. fixed code :


print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:")
if input == "C" then
rs.setOuput("top", true)
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleeep(1)
os.reboot()
else
if input == "P" then
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
if input == "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
else
print("Sorry that is not a valid order!")
os.reboot()
end
end
end
3. errors u had:

print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:") then -- U SHALL NOT PUT A then AFTER A term.write()
if input = "C" then -- U SHALL USE == INSTEAD OF = WHEN USING IF
rs.setOuput("top", true)
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleeep(1)
os.reboot()
else
if input = "P" then
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
if input = "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
os.reboot()
else
print("Sorry that is not a valid order!")
-- U SHALL END UR IF`S WITH end
os.reboot()
Drsirdeath #3
Posted 24 July 2012 - 09:25 PM
Alright that works. but then it wont let me put in my order. It just tells me what my choices are then finishes the program.

Also how do I use code tags?
Cranium #4
Posted 25 July 2012 - 04:06 AM

-- function to repeat tedious coding with one line.
function newpage()
term.clear()
print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:")
end
-- end function
while true do --needs to start the loop or else it just ends after first selection.
newpage()
input = io.read() -- detects typed input by user, and waits for "enter" before continuing.
if input == "C" then
rs.setOutput("top", true)   --small typo
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleep(1)	 --typo
newpage()
elseif input == "P" then  -- needs to be elseif instead of else
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
newpage()
elseif input == "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
newpage()
else
print("Sorry that is not a valid order!")
os.reboot()
end
end

Slightly fixed code with notes. Just some minor tweaks.

and to add code tags, just click the button that looks like this: <> in your text editor on the webpage, or if using a device that won't display it, simply add "(CODE)" at the beginning, and "(/CODE)" at the end, and replace the "( )" with "[ ]"

Edit: Derp, just realized you had os.reboot at the end of each selection. Hang on, I got it…
Edited on 25 July 2012 - 02:18 AM
Drsirdeath #5
Posted 25 July 2012 - 04:42 AM
Thanks! both of you! without your help i would be slamming my head up against the wall XD.

Anyway thanks for the help. It's Much appreciated.
Kolpa #6
Posted 25 July 2012 - 08:40 PM

-- function to repeat tedious coding with one line.
function newpage()
term.clear()
print("What would you like to eat today")
sleep(1)
print("Type C for cookies")
sleep(.5)
print("type P for pork")
sleep(.5)
print("And type A for apples")
term.write("Order:")
end
-- end function
while true do --needs to start the loop or else it just ends after first selection.
newpage()
input = io.read() -- detects typed input by user, and waits for "enter" before continuing.
if input == "C" then
rs.setOutput("top", true)   --small typo
sleep(1)
rs.setOutput("top.false")
print("Thank for ordering!")
sleep(1)	 --typo
newpage()
elseif input == "P" then  -- needs to be elseif instead of else
rs.setOutput("left", true)
sleep(1)
redstone.setOutput("left", false)
print("Thank you for ordering!")
sleep(1)
newpage()
elseif input == "A" then
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
print("Thank you for ordering!")
sleep(1)
newpage()
else
print("Sorry that is not a valid order!")
os.reboot()
end
end

Slightly fixed code with notes. Just some minor tweaks.

and to add code tags, just click the button that looks like this: <> in your text editor on the webpage, or if using a device that won't display it, simply add "(CODE)" at the beginning, and "(/CODE)" at the end, and replace the "( )" with "[ ]"

Edit: Derp, just realized you had os.reboot at the end of each selection. Hang on, I got it…
uh jeah that was my bad i was kinda tired at that time (actually pretty hungover :)/>/>)
Cranium #7
Posted 25 July 2012 - 09:00 PM
uh jeah that was my bad i was kinda tired at that time (actually pretty hungover :D/>/>)
I figured as much, it just didn't measure up to your previous help, so thought I would help out a bit. :)/>/>
Cranium #8
Posted 25 July 2012 - 09:15 PM
Thanks! both of you! without your help i would be slamming my head up against the wall XD.

Anyway thanks for the help. It's Much appreciated.
One question though, how are you deploying the food? I assume just plain dispensers? If so, you could greatly expand your selection by adding more foodstuffs/dispensers, and using a bundled wire and colored wire to send signals to each different one.
It requires a little more work, but the effect is more impressive. All you would have to do is use the command:

function foodType()
rs.setBundledOutput("side",colors.combine(colors.red,true)) --just specify the color to the food, and designate which side the bundled cable is touching the computer.
sleep(.5)
rs.setBundledOutput("side",colors.subtract(colors.red,false)) --makes it just pulse for .5 seconds.
end
Instead of foodType enter the name of whatever you want so that you know when you are calling back to this function, what food it is.
Drsirdeath #9
Posted 26 July 2012 - 12:00 AM
Thanks! both of you! without your help i would be slamming my head up against the wall XD.

Anyway thanks for the help. It's Much appreciated.
One question though, how are you deploying the food? I assume just plain dispensers? If so, you could greatly expand your selection by adding more foodstuffs/dispensers, and using a bundled wire and colored wire to send signals to each different one.
It requires a little more work, but the effect is more impressive. All you would have to do is use the command:

function foodType()
rs.setBundledOutput("side",colors.combine(colors.red,true)) --just specify the color to the food, and designate which side the bundled cable is touching the computer.
sleep(.5)
rs.setBundledOutput("side",colors.subtract(colors.red,false)) --makes it just pulse for .5 seconds.
end
Instead of foodType enter the name of whatever you want so that you know when you are calling back to this function, what food it is.

Excellent idea! i'll have to try it.