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

Why doesnt work my program?

Started by Cyan Crafter, 17 May 2012 - 02:05 PM
Cyan Crafter #1
Posted 17 May 2012 - 04:05 PM
Hi,

Ive made a little program (using with wireless redstone mod) that can turning on and off the lights, and let the lights flicker like a alarm sign.
But when i start the program it says bios:206: [string "light"]:23: unexpected symbol
i know what it means i guess, but i havent found any mistake on line 23 or anywhere in the code. (but it have to be…)
maybe can somebody find it, and then solve the problem :P/>/>

heres the code:


print "Loading the light-system…"
sleep(1)
print "Loading Done!"
print "Choose an option:"
term.setCursorPos (5,5)
print "a. Lights On."
print "b. Lights Off."
print "c. SOS Sign."

on = read()
if on == "a" then
sleep(1)
print "Lights on!"
print "Clearing Screen…"
redstone.setOutput ("bottom", true)
sleep(5)
term.clear()
term.setCursorPos (1,1)

elseif

if on == "b" then
sleep(1)
print "Lights off!"
print "Clearing Screen…"
redstone.setOutput ("bottom", false)
sleep(5)
term.clear()
term.setCursorPos (1,1)

elseif

if on == "c" then
print "SENDING OUT SOS SIGN!"
sleep(1)
print "SOS SIGN SENDED!"
print "Terminate with CTRL T"
while true do
redstone.setOutput ("bottom", true)
sleep(1)
redstone.setOutput ("bottom", false)

else
print "Unknown Command."

end


i hope somebody can figure it out, i know somebody can :D/>/>

thx for reading my post ;p
- CyanCrafter
MysticT #2
Posted 17 May 2012 - 04:20 PM
The if syntax is wrong. It's:

if <condition1> then
  -- condition1 is true, do something
elseif <condition2> then
  -- condition1 is false but condition2 is true, do something
else
  -- both conditions are false, do something else
end
You don't have to use the elseif and the else (they are not required), just if you need them, but that's the syntax for it.
Cyan Crafter #3
Posted 17 May 2012 - 04:24 PM
The if syntax is wrong. It's:

if <condition1> then
  -- condition1 is true, do something
elseif <condition2> then
  -- condition1 is false but condition2 is true, do something
else
  -- both conditions are false, do something else
end
You don't have to use the elseif and the else (they are not required), just if you need them, but that's the syntax for it.

okay..?
could you place it in the whole code please? then i can just copy it, :P/>/>
MysticT #4
Posted 17 May 2012 - 05:14 PM
Well, the idea of the mod is to code for yourself, so try doing it. All you have to do is change the lines:

elseif
if ...
to

elseif ...
Remove the second if on each statement.
Example:

elseif

if on == "b" then
would be:

elseif on == "b" then
Loopin #5
Posted 17 May 2012 - 05:14 PM

print "Loading the light-system..."
sleep(1)
print "Loading Done!"
print "Choose an option:"
term.clear()
term.setCursorPos (5,5)
print "a. Lights On."
print "b. Lights Off."
print "c. SOS Sign."
on = read()
if on == "a" then
	  sleep(1)
	  print "Lights on!"
	  print "Clearing Screen..."
	  redstone.setOutput ("bottom", true)
	  sleep(5)
	  term.clear()
	  term.setCursorPos (1,1)
elseif on == "b" then
	 sleep(1)
	 print "Lights off!"
	 print "Clearing Screen..."
	 redstone.setOutput ("bottom", false)
	 sleep(5)
	 term.clear()
	 term.setCursorPos (1,1)
elseif on == "c" then
	  print "SENDING OUT SOS SIGN!"
	  sleep(1)
	  print "SOS SIGN SENDED!"
	  print "Terminate with CTRL T"
	  while true do
		 redstone.setOutput ("bottom", true)
		 sleep(1)
		 redstone.setOutput ("bottom", false)
	    end
else
print "Unknown Command."
end


This is the correct code, but if you just copy, how you gonna learn?

you cant do:


elseif
if

you do:

elseif c=="blablabla" then
elseif c=="blebleble" then
else
Cyan Crafter #6
Posted 17 May 2012 - 05:33 PM
ohhh! now i totally get it :D/>/>
thx to MysticT for explainasion and thx to Loopin for putting it in de whole code, so i dont have to dot that anymore :P/>/>

thx