21 posts
Posted 01 September 2014 - 11:32 PM
I'm can't get this code to work;
Local t = read()
Local g = read()
if t = "A1" then
commandExit()
elseif g = "A2" then
commandGames()
end
end
It Keeps Saying; :3: 'then' expected
The three is not part of the error, it's just I put that there so that you guys know where the error is supposedly located.
18 posts
Posted 01 September 2014 - 11:40 PM
The problem is that you need to put '==' instead of '=' on lines 3 and 5. = is used for setting a variable, == is the boolean operator for checking if two things are equal. Also, the last end should not be there. elseif and else do not require another end. Local should also be local, it is case sensetive.
Here's the fixed code:
local t = read()
local g = read()
if t == "A1" then
commandExit()
elseif g == "A2" then
commandGames()
end
Edited on 01 September 2014 - 09:42 PM
1220 posts
Location
Earth orbit
Posted 01 September 2014 - 11:41 PM
The exact error (with the line number) would be most helpful. In this case, your error is with your comparitors. Instead of
if t = "A1" then
You are comparing a variable not setting a variable so you would use this
if t == "A1" then
Fix that with both your "A1" and "A2" comparitors and it should work.
EDIT: :ph34r:/> 'd
Edited on 01 September 2014 - 09:42 PM
1080 posts
Location
In the Matrix
Posted 01 September 2014 - 11:41 PM
Local t = read()
Local g = read()
if t = "A1" then
commandExit()
elseif g = "A2" then
commandGames()
end
end
line 3 is
if t = "A1" then
your problem is that lua uses = to set a value and == to compare a value, so you should have it as
if t == "A1" then
same for your elseif, and i'm going to assume that commandExit() and commandGames() are already defined functions, if they are below this bit then you're going to error.
EDIT: double :ph34r:/>'d
Edited on 01 September 2014 - 09:42 PM
21 posts
Posted 02 September 2014 - 12:33 AM
Thnkz.
Btw, will this code allow me to activate both functions at once? commandGames() + commandExit()
7083 posts
Location
Tasmania (AU)
Posted 02 September 2014 - 01:09 AM
No.
The best way to go about it would depend on what those functions actually do.
21 posts
Posted 02 September 2014 - 01:16 AM
They both have commands you type in to the terminal and it would bring up an ASCII style menu. Every time I try to make it to where you can pick which one you wanna do, it will only allow you to do one or error.
7083 posts
Location
Tasmania (AU)
Posted 02 September 2014 - 01:26 AM
What I suspect is that you want to do this:
local t = read()
if t == "A1" then
commandExit()
elseif t == "A2" then
commandGames()
end
If not, then you'll need to elaborate. By "do one", do you mean you can only get one of the two options to work, full stop? If so, which? Or do you mean you can do one or the other, but not both at the same time? What does the error
say?
21 posts
Posted 02 September 2014 - 01:39 AM
Thnkz, it is working now.