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

[Lua][Error] 'then' expected - No idea the problem

Started by orbiter54321, 29 March 2012 - 12:01 AM
orbiter54321 #1
Posted 29 March 2012 - 02:01 AM
Hello, I'm very new to computercraft and even newer to LUA (today haha)

and I'm trying to make a simple multi on/off switch right now, in which case here is the code:


print("Welcome to the main control panel")
sleep(1)
term.clear()
sleep(1)
term.setCursorPos(1,1)
print("Would you like to change properties of...")
print("1   Engines")
print("2   Tree Farm")
print("3   Peat Farm")
sleep(1)
local comp = io.read()
if comp == "1" then
term.clear()
term.setCursorPos(1,1)
print("Engine Control")
print("Current status:")
if redstone.test.BundledInput("back", colors.white) = true then <---- everythig worked fine until I input this line onward
print("Active")
if redstone.test.BundledInput("back", colors.white) = false then
print("Inactive")

and tehn when I try and run it I get this eror:

Main (program name)
bios:206: [string"Main"]:17: 'then' expected

if it helps I have tekkit installed so there is computercraft and redpower

I have no idea what to do, I've look at the debugging page and it didn't help, plus google'd for like an hour :o/>/>

thanks for any help!
Advert #2
Posted 29 March 2012 - 02:06 AM
You're using = instead of ==. On top of that, you've forgotten to close your if statement!
You can also use else instead of checking again:

if condition then
 stuff()
else
 otherstuff()
end

You also don't need to check if it's true:
In Lua, an if statement will pass as long as the condition is not false or nil:

if true then stuff() end -- this will pass
if not true then stuff() end -- this will not pass
if someFunction() then stuff() end -- this will pass if someFunction returns something other than nil or false.
if nil then stuff() end -- will not pass
if false then stuff() end -- will not pass
cant_delete_account #3
Posted 29 March 2012 - 02:31 AM
Here's the fixed code:

print("Welcome to the main control panel")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Would you like to change properties of...")
print("1   Engines")
print("2   Tree Farm")
print("3   Peat Farm")
sleep(1)
local comp = read()
if comp == "1" then
term.clear()
term.setCursorPos(1,1)
print("Engine Control")
if redstone.test.BundledInput("back", colors.white) then
term.clear()
term.setCursorPos(1,1)
write("Current status: ")
write("Active")
else if not redstone.test.BundledInput("back", colors.white) then
term.clear()
term.setCursorPos(1,1)
write("Current status: ")
write("Inactive")
end
end
Should work.
EDIT: Oopsy forgot some stuff might wanna copy it again.
orbiter54321 #4
Posted 29 March 2012 - 02:38 AM
Here's the fixed code:

print("Welcome to the main control panel")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Would you like to change properties of...")
print("1   Engines")
print("2   Tree Farm")
print("3   Peat Farm")
sleep(1)
local comp = read()
if comp == "1" then
term.clear()
term.setCursorPos(1,1)
print("Engine Control")
if redstone.test.BundledInput("back", colors.white) then
term.clear()
term.setCursorPos(1,1)
write("Current status: ")
write("Active")
else if not redstone.test.BundledInput("back", colors.white) then
term.clear()
term.setCursorPos(1,1)
write("Current status: ")
write("Inactive")
end
end
Should work.
EDIT: Oopsy forgot some stuff might wanna copy it again.
Thank you so much for the reply!
You're using = instead of ==. On top of that, you've forgotten to close your if statement!
You can also use else instead of checking again:

if condition then
stuff()
else
otherstuff()
end

You also don't need to check if it's true:
In Lua, an if statement will pass as long as the condition is not false or nil:

if true then stuff() end -- this will pass
if not true then stuff() end -- this will not pass
if someFunction() then stuff() end -- this will pass if someFunction returns something other than nil or false.
if nil then stuff() end -- will not pass
if false then stuff() end -- will not pass
Thank you for explaining, and thank!

To both: Thank you so much for the help, sorry if it was a bother or inconvienience
Advert #5
Posted 29 March 2012 - 03:16 AM

To both: Thank you so much for the help, sorry if it was a bother or inconvienience

Not at all, glad to help :o/>/>
Hawk777 #6
Posted 01 April 2012 - 06:11 AM
Also, the correct function is “redstone.testBundledInput”, not “redstone.test.BundledInput”.