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

[LUA][Error] 'then' expected

Started by Mackan90096, 12 March 2013 - 08:52 AM
Mackan90096 #1
Posted 12 March 2013 - 09:52 AM
Hi! Im trying to make a program for booking rooms like in hotels.
I want to make it check if the room´s booked or not and if its booked do one thing and if its not booked do another thing..
But when i try to run it i get this error message: bios:388: [string "startup"]:29: 'then' expected
I've tried to figure out how to fix it but i cant find any information on it …
Please help me.
Well.. anyways heres the script:


room1 = false
room2 = false

function start()
term.clear()
term.setCursorPos(1,1)
print("[1] Booking")
term.setCursorPos(1,2)
print("[2] Unbooking")
term.setCursorPos(1,3)
write("Input number: ")
local input = read()
if input == "1" then
book()
elseif input == "2" then
unbook()
else
start()
end
end

function book()
term.clear()
term.setCursorPos(1,1)
print("Booking")
term.setCursorPos(1,2)
write("What room would you like to book?: ")
local input = read()
if input == "1" and (room1) = false then
term.clear()
term.setCursorPos(1,1)
print("debug")
end
end

start()
TheJeremail #2
Posted 12 March 2013 - 10:09 AM
Simple mistake, happens to me quite a lot, too:

if input == "1" and (room1) = false then
has to be
if input == "1" and (room1) == false then
(double "=" )

Hope that helped :D/>
LBPHacker #3
Posted 12 March 2013 - 10:30 AM
not room1
is better than
room1 == false
Unless you REALLY want 'false', because if room1 is nil, (not room1) still evaluates true

I just can't believe that half of the programmers on this forum have never heard about or can't use 'boolean' properly…
Mackan90096 #4
Posted 12 March 2013 - 06:32 PM
Ah. Thanks for The help!
theoriginalbit #5
Posted 12 March 2013 - 06:47 PM
not room1
is better than
room1 == false
Unless you REALLY want 'false', because if room1 is nil, (not room1) still evaluates true

I just can't believe that half of the programmers on this forum have never heard about or can't use 'boolean' properly…
There is an advantage to using direct boolean checking, take this example

local function someFunc( someVar )
  if not someVar then
    print( [[You supplied boolean 'false']] )
  end
end
that would have problems with

someFunc('hello')

So in this case using

if someVar == false then
would be better evaluation… it is one disadvantage to Lua not forcing types.