3 posts
Posted 14 October 2016 - 07:58 AM
Hi,
I've just created this program and I have some trouble with it
It's asking me to put a then at the end of the line 5,and I dont know why
There is the code below :
If you couls help me that would be great !!!
m = peripheral.wrap("back")
rednet.open("left")
message = rednet.recieve()
if message = blue then
m.setBackgroundColor(colors.blue)
sleep(2)
os.reboot()
end
if message = red then
m.setBackgroundColor(colors.red)
sleep(2)
os.reboot()
end
7083 posts
Location
Tasmania (AU)
Posted 14 October 2016 - 01:58 PM
As a rule, if you're told "such and such is expected", it doesn't necessarily mean it's
missing from the line - it means you've put something
unacceptable where "such and such "
could go.
In this case you've stuck the assignment operator, "=", there. You meant to use "==", the "is equal to" comparator. Probably also a good idea to stick quotes around those strings and to fix those typos!
local m = peripheral.wrap("back") --# See http://lua-users.org/wiki/ScopeTutorial re "local" and scope
rednet.open("left")
while true do --# http://lua-users.org/wiki/ControlStructureTutorial Better to specifically set up a loop than to reboot the computer!
local sender, message = rednet.receive() --# http://www.computercraft.info/wiki/Rednet.receive - spelling + returns more than one value!
if message == "blue" then
m.setBackgroundColor(colors.blue) --# This just changes the drawing colour, without affecting the current display...
m.clear() --# This redraws the whole display with the current background colour.
sleep(2)
elseif message == "red" then
m.setBackgroundColor(colors.red)
m.clear()
sleep(2)
end
end
Edited on 14 October 2016 - 11:59 AM
3 posts
Posted 14 October 2016 - 04:41 PM
I fixed it and …. it worked thanks a lot It means a lot thanks
Added later :
What if I want to add some other condition ?Do I add another elseif or do I add an other if statement ?
Edited on 14 October 2016 - 05:30 PM
23 posts
Posted 15 October 2016 - 01:09 AM
I fixed it and …. it worked thanks a lot It means a lot thanks
Added later :
What if I want to add some other condition ?Do I add another elseif or do I add an other if statement ?
It could be any, just note that the code reader reads the code top to bottom. So it will check the first If statement, then move to the next If (Or elseif) statements.
7083 posts
Location
Tasmania (AU)
Posted 15 October 2016 - 02:23 AM
That control structure tutorial I linked has more info on "if" statements.
3 posts
Posted 15 October 2016 - 09:27 AM
I fixed it and …. it worked thanks a lot It means a lot thanks
Added later :
What if I want to add some other condition ?Do I add another elseif or do I add an other if statement ?
It could be any, just note that the code reader reads the code top to bottom. So it will check the first If statement, then move to the next If (Or elseif) statements.
That control structure tutorial I linked has more info on "if" statements.
Ok thanks to both of you.Bye