这是 Corona SDK 中游戏的 Lua 脚本。起初(旧代码)效率非常低,我必须在某人的帮助下使用(新代码)手动创建每个数学问题,所以我明白了。
在控制台中我现在收到此错误:
第 93 行:本地 QuestionText = display.newText(questionGroup, questions[currentQuestion].question, 0,0, chalkfFont, 34 )
game.lua:93: 'newText' 的错误参数#2(预期字符串,为零)
--mathQuestions.lua (Old code)
local M = {}
M["times"] = {
{
question="6 x 5", --The question.
answers={"30", "11", "29", "20"}, --Array of possible answers.
answer=1 --Which one from the above array is the correct answer.
},
}
return M
--mathQuestions.lua (New code)
local rnd = function (x) return math.random(1,x) end
M.times = {}
local numQuestions = 10 -- how many questions in your database
for i=1,numQuestions do
local obj =
{
left=math.random(1,10),
right=math.random(1,10),
answers={rnd(100), rnd(100), rnd(100), rnd(100)},
answerIndex=rnd(4) -- will override answer[answerIndex] later
}
obj.answer = obj.left * obj.right
obj.answers[obj.answerIndex] = obj.answer
M.times[i] = obj
end
关于问题是什么以及如何解决它有什么想法吗?谢谢。
最佳答案
第 93 行有“questions[currentQuestion].question”:问题表中的每个项目都是一个包含字段“左”、“右”等的表,但没有您在第 93 行访问的字段“问题”。在循环中在定义问题的地方,在“obj.answer =":
之前添加一行obj.question = string.format("%s x %s", left, right)
关于Lua 错误 : string expected, 为零 --- 错误的参数 #2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21961207/