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

Geting a "then excepted" error message

Started by CupricWolf, 29 February 2012 - 12:18 PM
CupricWolf #1
Posted 29 February 2012 - 01:18 PM
My program keeps getting the error message "then excepted" even though I have then in my program. My program is designed to receive input of 1-8 and then output different combinations of colors in the red power mod, the different combinations power different segments on a 7 segment display.
The program looks like this:
read() = x
If x = 1
then
redset bottom magenta true
redset bottom lime true
end
If x = 2
then
redset bottom black true
redset bottom lime true
redset bottom orange true
redset bottom red true
redset bottom white true
End
And it continues all the way to 8. But the error I get is that I'm missing then on line 3 which is the line that is then. Could anybody help?
Liraal #2
Posted 29 February 2012 - 01:21 PM
It should be

If
x == 1
'=' is setting a value, '==' compares two values
CupricWolf #3
Posted 29 February 2012 - 01:23 PM
Ok I'll see if that works. I'm at school now, in passing period, so when I get home I'll try this.
Hawk777 #4
Posted 29 February 2012 - 08:37 PM
Also, you're confusing command-line programs with Lua functions. "redset" is a command-line utility. If you want to do the same in Lua, you have to use the corresponding functions. For example, your lines:

redset bottom magenta true
redset bottom lime true

should be replaced with this:

redstone.setBundledOutput("bottom", colors.combine(colors.magenta, colors.lime))
MysticT #5
Posted 29 February 2012 - 09:05 PM
Also, a few things:
* Remember that lua is case sensitive, so you should write "if" instead of "If" and "end" instead of "End".
* it should be:

local x = read()
not:

read() = x
* read() returns a string, so comparing it with a number will always return false. You have to use tonumber, something like this:

local x = tonumber(read())
* Always try to use local variables, avoid globals if you can. (Use local in front of the variable definition)
CupricWolf #6
Posted 29 February 2012 - 10:32 PM
Ok thanks all, I have to Finnish homework and will try this soon

Grrr auto correct corrected finish to Finnish
CupricWolf #7
Posted 29 February 2012 - 10:38 PM
I could also compare to a string too
x == "1"
CupricWolf #8
Posted 29 February 2012 - 10:55 PM
It worked. Thank you very much, all of you :unsure:/>/> I'm just using numerical comparisons too