当尝试在Corona SDK上使用LUA比较2个整数变量时,出现一个非常奇怪的错误。
基本上这就是我所拥有的
**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
继承人的问题,即使得到“Answer = 1,jAnswer = 1”之类的输出,我仍然会收到“错误答案”。
最佳答案
基本上,jAnswer被视为一个字符串,所以我只需要使用lua上名为tonumber()
的全局类将字符串转换为数字
jAnswer = tonumber(jAnswer, 10) -- Convert using the decimal base
谢谢!