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

help me feeling not so dumb... (simple stuff)

Started by slashv2, 07 January 2013 - 04:13 AM
slashv2 #1
Posted 07 January 2013 - 05:13 AM
Hi i've never coded before in my long life, but im reading up on it :D/> and im starting to understand a few things (your gonna laugh when you see the code, and how simple it is, and yet not working)

i wanted to make a small little food machine as a test, using 3 dispensers (i know you could probably use a turtle as a food dispensing robot, but i also know im quite limited ,P)

can someone explain in simple mans terms why this is not working?
It starts up right and prints the menu.. but then it's like it thinks it's done and terminates the script..

I've looked at the code for quite some time and tried a few things, none of wich worked



print("Welcome to the Food master1000")
   name = io.read
   sleep(2)
   print(" |-=menu=-|")
   print(" |1: Steak|")
   print(" |2: Pork |")
   print(" |3: Soup |")


if name == "1" then
   redstone.setOutput("left",true)
   print("Steak it is!")
   sleep(1)
   term.clear()
   redstone.setOutput("left",false)
   os.reboot()
end

if name == "2" then
   redstone.setOutput("back",true)
   print("Pork it is!")
   sleep(1)
   term.clear()
   redstone.setOutput("back",false)
   os.reboot()
end

if name == "3" then
   redstone.setOutput("right",true)
   print("Soup it is!")
   sleep(1)
   term.clear()
   redstone.setOutput("right",false)
   os.reboot()
end

See i just knew you would laugh :(/>
Orwell #2
Posted 07 January 2013 - 05:17 AM
Don't worry, everyone makes these mistakes. :)/>
Change

name = io.read
to:

name = io.read()
io.read is a function and therefor needs parentheses after the name to call it.
Goof #3
Posted 07 January 2013 - 05:21 AM
instead of use

if name == "1" then

-- do code

end

if name == "2" then

--- etc...

then use the elseif.

like this: ( it would just be a bit easier to read :D/>) ( in my way )

if name == "1" then
--do stuff--
elseif name == "2" then
-- do stuff 2--
elseif name == "3" then
-- do stuff 3 --
end

and then in your "io.read" you miss the two parantheses at the end:

name = io.read
should be

name = io.read()


i hope i could help :D/>
remiX #4
Posted 07 January 2013 - 05:28 AM
Also, put io.read() after it prints the menu:


print("Welcome to the Food master1000")
   print(" |-=menu=-|")
   print(" |1: Steak|")
   print(" |2: Pork |")
   print(" |3: Soup |")
   sleep(2) 
name = io.read
Orwell #5
Posted 07 January 2013 - 05:29 AM
Also, put io.read() after it prints the menu:


print("Welcome to the Food master1000")
   print(" |-=menu=-|")
   print(" |1: Steak|")
   print(" |2: Pork |")
   print(" |3: Soup |")
   sleep(2)
name = io.read
Lol, yea. But of course, still with the parentheses: io.read() .
slashv2 #6
Posted 07 January 2013 - 05:38 AM
ohh Wow… how did i miss that o.0 funny how you can miss small things like that when sitting and look intensely at it ;P

Thanks guys! you work :D/> heh And thanks for not laughing too much ;P

xD just saw my forum member status "Clueless" could not be more right xD
remiX #7
Posted 07 January 2013 - 08:48 AM
Also, put io.read() after it prints the menu:


print("Welcome to the Food master1000")
   print(" |-=menu=-|")
   print(" |1: Steak|")
   print(" |2: Pork |")
   print(" |3: Soup |")
   sleep(2)
name = io.read
Lol, yea. But of course, still with the parentheses: io.read() .

Oh woops, lol I copied his code and forgot to add it in xD