Reputation: 1123
I'm getting a very strange error, when trying to compare 2 integer variables using LUA on Corona SDK.
Basically this is what i have
**jAnswer** -- is a variable set via jSON, the value can only be 0 or 1.
local function checkAnswer(answer)
if (answer == jAnswer ) then
print("Correct Answer")
print("Answer is = "..answer.." jAnswer = "..jAnswer)
else
print("Wrong Answer")
print("Answer is = "..answer.." jAnswer = "..jAnswer)
end
end
checkAnswer(1) -- Calling the Function Here
Heres the problem, even if a get a output like "Answer is = 1, jAnswer = 1", i still get the "Wrong Answer".
Upvotes: 3
Views: 1513
Reputation: 1123
Basically, the jAnswer, was being seen as a String, so i just needed to convert the string to number, using a global class on lua named tonumber()
jAnswer = tonumber(jAnswer, 10) -- Convert using the decimal base
Thanks!
Upvotes: 4