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

error for then when i have a then?

Started by bharhal, 21 February 2016 - 12:42 AM
bharhal #1
Posted 21 February 2016 - 01:42 AM
so i have a program for a city apartment complex that im building and i have a gui for it and a menu. when i run it, it says that it needs a then but there is already one there and i cant figure out the bug if anyone can help here is the code
btw the error is - "bios:14: [string "gui"]:32: 'then' expected

local sid = 0

function menu(id, text)
if sid == id then
write(">")
else
write(" ")
end
print(text)
end

while true do
term.clear()
term.setCursorPos(1,1)
print("+—CraftCity Apartment's—+")
print("| Who Are You? |")
print("| |")
print("| |")
print("| |")
print("| |")
print("+———————————+")
term.setCursorPos(3,14)
menu(0, "Owner")
term.setCursorPos(5,14)
menu(1, "Customer")
event, key = os.pullEvent("key")
if key == 200 then
if sid > 0 then
sid = sid - 1
end
elseif key == 28 then
sleep(1)
elseif sid == 1 then
sleep(1)
end
end
end
KingofGamesYami #2
Posted 21 February 2016 - 02:04 AM
The proper structure for an if/elseif statement looks like this:


if a then

elseif b then

elseif c then

end

You have one too many ends:


if sid > 0 then
  side = sid - 1
end --#this one should be removed
elseif key == 28 then
  sleep( 1 )
elseif sid == 1 then
  sleep( 1 )
end

This will solve this error, but will not allow your program to function. The sleep( 1 ) will "eat" all the events the user generates by pressing keys. Which will obviously mean you will never be able to act on those inputs.
Edited on 21 February 2016 - 02:59 PM
bharhal #3
Posted 21 February 2016 - 02:11 AM
The proper structure for an if/elseif statement looks like this:


if a then

elseif b then

elseif c then

end

You have one too many ends:


if sid > - then
  side = sid - 1
end --#this one should be removed
elseif key == 28 then
  sleep( 1 )
elseif sid == 1 then
  sleep( 1 )
end

This will solve this error, but will not allow your program to function. The sleep( 1 ) will "eat" all the events the user generates by pressing keys. Which will obviously mean you will never be able to act on those inputs.

i have erased the end like you suggested but for some reason it says that a then is expected on line 31 :/
Bomb Bloke #4
Posted 21 February 2016 - 08:24 AM
The code you've posted won't produce that error.

The VM is telling you that you've put either an illegal keyword or symbol into an "if" statement around that line - it's not so much complaining that what's expected is missing, so much as what's unexpected is there before getting to it.