Jump to content




bios:366: [string "startup"]:5: 'then' expected


  • You cannot reply to this topic
5 replies to this topic

#1 Tf_Chronikeur

  • Members
  • 3 posts

Posted 14 October 2016 - 06: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

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 October 2016 - 12: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 by Bomb Bloke, 14 October 2016 - 12:59 PM.


#3 Tf_Chronikeur

  • Members
  • 3 posts

Posted 14 October 2016 - 03: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 by Tf_Chronikeur, 14 October 2016 - 06:30 PM.


#4 fatboychummy

  • Members
  • 25 posts

Posted 15 October 2016 - 12:09 AM

View PostTf_Chronikeur, on 14 October 2016 - 03:41 PM, said:

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.

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 October 2016 - 01:23 AM

That control structure tutorial I linked has more info on "if" statements.

#6 Tf_Chronikeur

  • Members
  • 3 posts

Posted 15 October 2016 - 08:27 AM

View Postfatboychummy, on 15 October 2016 - 12:09 AM, said:

View PostTf_Chronikeur, on 14 October 2016 - 03:41 PM, said:

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.

View PostBomb Bloke, on 15 October 2016 - 01:23 AM, said:

That control structure tutorial I linked has more info on "if" statements.

Ok thanks to both of you.Bye





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users