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

Newbie Program error ""=" expected"

Started by Jpaulding14, 09 August 2012 - 04:03 PM
Jpaulding14 #1
Posted 09 August 2012 - 06:03 PM
This is my first code I am trying to make a food dispenser based on input choice of 4 different foods.
I think I may have done EVERYTHING wrong. I have been trying to fix it for about an hour now and have no idea how to.

Code so far:


term.clear()
term.setcursorpos(1,1)
write("Would You Like Apples, Porkchops, Steak Or Chicken")
if input == "Apples" then
redpulse right
sleep(1)
end
else
if input == "Porkchops" then
redpulse left
sleep(1)
end
else
if input == "Steak" then
redpulse top
sleep(1)
end
else
if input == "Chicken" then
redpulse bottom
sleep(1)
end
else
if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
Matrixmage #2
Posted 09 August 2012 - 06:07 PM
I think the syntax for redpulse is

redpulse(side)
or

redpulse("side")
Can't remember sorry ;)/>/> The reason you got that error is that it thought you were using redpulse as a veriable which you have to use a "=" for
Jpaulding14 #3
Posted 09 August 2012 - 06:11 PM
I think the syntax for redpulse is

redpulse(side)
or

redpulse("side")
Can't remember sorry ;)/>/> The reason you got that error is that it thought you were using redpulse as a veriable which you have to use a "=" for
So what you are saying I need to do this?

term.clear()
term.setcursorpos(1,1)
write("Would You Like Apples, Porkchops, Steak Or Chicken")
if input == "Apples" then
redpulse("right")
sleep(1)
end
else
if input == "Porkchops" then
redpulse("left")
sleep(1)
end
else
if input == "Steak" then
redpulse("top")
sleep(1)
end
else
if input == "Chicken" then
redpulse("bottom")
sleep(1)
end
else
if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
Matrixmage #4
Posted 09 August 2012 - 06:14 PM
I think the syntax for redpulse is

redpulse(side)
or

redpulse("side")
Can't remember sorry ;)/>/> The reason you got that error is that it thought you were using redpulse as a veriable which you have to use a "=" for
So what you are saying I need to do this?

term.clear()
term.setcursorpos(1,1)
write("Would You Like Apples, Porkchops, Steak Or Chicken")
if input == "Apples" then
redpulse("right")
sleep(1)
end
else
if input == "Porkchops" then
redpulse("left")
sleep(1)
end
else
if input == "Steak" then
redpulse("top")
sleep(1)
end
else
if input == "Chicken" then
redpulse("bottom")
sleep(1)
end
else
if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
Ya, after think about it I'm almost positive that the quotes are needed for the name of the side, so that's right
Jpaulding14 #5
Posted 09 August 2012 - 06:17 PM
What you said fixed one error but I have another one too.
I get "bios:206: [string "Food"]:8: '<eof>' expected"

term.clear()
term.setcursorpos(1,1)
write("Would You Like Apples, Porkchops, Steak Or Chicken")
if input == "Apples" then
redpulse("right")
sleep(1)
end
else
if input == "Porkchops" then
redpulse("left")
sleep(1)
end
else
if input == "Steak" then
redpulse("top")
sleep(1)
end
else
if input == "Chicken" then
redpulse("bottom")
sleep(1)
end
else
if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
Matrixmage #6
Posted 09 August 2012 - 06:19 PM
on line 8 you put a end then a else ;)/>/>
get rid of the end on line 7
Matrixmage #7
Posted 09 August 2012 - 06:21 PM
also on line 12 and line 17 and line 22
Jpaulding14 #8
Posted 09 August 2012 - 06:23 PM
on line 8 you put a end then a else ;)/>/>
get rid of the end on line 7
Sweet after fixing that I now have
":20: 'then' expected"

else
if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
This is Where the problem is
Matrixmage #9
Posted 09 August 2012 - 06:25 PM
which line is line 20? also use a elseif rather then a else and a if
Jpaulding14 #10
Posted 09 August 2012 - 06:27 PM
which line is line 20? also use a elseif rather then a else and a if

else
#20 if input ~= "Chicken", "Steak", "Porkchops", "Apples" then
print("Invalid Input")
sleep(1)
end
Matrixmage #11
Posted 09 August 2012 - 06:33 PM
hmmm, can't see the problem, I'll try it in my game, give me a sec, also try replacing all the else fallowed by if's by the elseif, it might fix it.
Cranium #12
Posted 09 August 2012 - 06:39 PM
It is not letting you use commas for the other than equal operator. You would just need to use else(as long as you switch everything else to elseif). Nothing else would be needed, because you are saying "if this then do this, else if none of this, then do this"
Matrixmage #13
Posted 09 August 2012 - 07:05 PM
I think I got it to work, but the setcursorpos seems to hate me and it refused to work so I set it to reboot at the end of the code as I am assuming that this will be installed on a dedicated terminal, you can see if you can get the setcursorpos but I didn't want to spend the time on it. so set this as the startup and it will work, if you dont know how to get into the startup use fs.copy(nameofthisprogram, startup) while your in the lua shell program or make a small program with the fs.copy being the only contents


term.clear()
write("Would You Like Apples, Porkchops, Steak Or Chicken?")
input = read()
if input == "Apples" then
redpulse("right")
sleep(1)
else
if input == "Porkchops" then
redpulse("left")
sleep(1)
os.reboot()
else
if input == "Steak" then
redpulse("top")
sleep(1)
os.reboot()
else
if input == "Chicken" then
redpulse("bottom")
sleep(1)
os.reboot()
else
if input ~= "Chicken" or "Steak" or "Porkchops" or "Apples" then
print("Invalid Input")
sleep(1)
os.reboot()
end
end
end
end
end
Cranium #14
Posted 09 August 2012 - 07:17 PM
A few notes on the code, and some modifications.


term.clear()
write("Would You Like Apples, Porkchops, Steak Or Chicken?")
input = read()
if input == "Apples" then
redpulse("right")
sleep(1)
elseif input == "Porkchops" then --use elseif, or it will only use the first else.
redpulse("left")
sleep(1)
os.reboot()
elseif input == "Steak" then
redpulse("top")
sleep(1)
os.reboot()
elseif input == "Chicken" then
redpulse("bottom")
sleep(1)
os.reboot()
else --since we are using else, it is saying that if none of the above are entered, it will run this code below.
print("Invalid Input")
sleep(1)
os.reboot()
end
end
end
end
end
Matrixmage #15
Posted 09 August 2012 - 07:20 PM
A few notes on the code, and some modifications.


term.clear()
write("Would You Like Apples, Porkchops, Steak Or Chicken?")
input = read()
if input == "Apples" then
redpulse("right")
sleep(1)
elseif input == "Porkchops" then --use elseif, or it will only use the first else.
redpulse("left")
sleep(1)
os.reboot()
elseif input == "Steak" then
redpulse("top")
sleep(1)
os.reboot()
elseif input == "Chicken" then
redpulse("bottom")
sleep(1)
os.reboot()
else --since we are using else, it is saying that if none of the above are entered, it will run this code below.
print("Invalid Input")
sleep(1)
os.reboot()
end
end
end
end
end

I just noticed that I hadn't changed that and was going to re-post, Ninja'd ;)/>/>
Well that what I get for rushing :|
Cranium #16
Posted 09 August 2012 - 07:29 PM
I am da ninja… ;)/>/>
Jpaulding14 #17
Posted 09 August 2012 - 07:41 PM
Thanks a lot guys!
Matrixmage #18
Posted 09 August 2012 - 08:16 PM
Thanks a lot guys!
Your very welcome!