Corona sdk 连接 table 到其他 lua file.Error 错误参数#-1 newText
Corona sdk connecting table to other lua file.Error bad argument#-1 newText
我的 table 有问题。我无法将 table 连接到我的其他 lua 文件。我在本地 lblGiven = display.newText 上有一个错误。它显示 Error bad argument#-1 newText。该程序的机制是,如果您单击按钮,table 的单个部分将显示为标签。
这是我的文件 questions.lua
local M = {
{
"What is the answer 1",
answer = "17",
},
{
"What is the answer 2",
answer = "18",
},
{
"What is the answer 3",
answer = "25",
},
},
return M
这是我的 main.lua
local given = require("questions")
local lblGiven = display.newText(
{
text = given[math.random(#given)],
x = 160,
y = 310,
font = native.systemFont,
align = "center"
}
)
尝试
local M = {
{
"What is the answer 1",
answer = "17",
},
{
"What is the answer 2",
answer = "18",
},
{
"What is the answer 3",
answer = "25",
},
} -- remove comma
return M
和
local given = require("questions")
local lblGiven = display.newText(
{
text = given[math.random(#given)][1],
x = 160,
y = 310,
font = native.systemFont,
align = "center"
}
)
指令given[math.random(#given)]
给你table。例如 given[1]
等于 {"What is the answer 1", answer = "17"}
。要获得唯一的问题,您需要使用方括号和索引。从 Understanding lua tables in corona sdk 阅读更多关于 table 的信息。
我的 table 有问题。我无法将 table 连接到我的其他 lua 文件。我在本地 lblGiven = display.newText 上有一个错误。它显示 Error bad argument#-1 newText。该程序的机制是,如果您单击按钮,table 的单个部分将显示为标签。
这是我的文件 questions.lua
local M = {
{
"What is the answer 1",
answer = "17",
},
{
"What is the answer 2",
answer = "18",
},
{
"What is the answer 3",
answer = "25",
},
},
return M
这是我的 main.lua
local given = require("questions")
local lblGiven = display.newText(
{
text = given[math.random(#given)],
x = 160,
y = 310,
font = native.systemFont,
align = "center"
}
)
尝试
local M = {
{
"What is the answer 1",
answer = "17",
},
{
"What is the answer 2",
answer = "18",
},
{
"What is the answer 3",
answer = "25",
},
} -- remove comma
return M
和
local given = require("questions")
local lblGiven = display.newText(
{
text = given[math.random(#given)][1],
x = 160,
y = 310,
font = native.systemFont,
align = "center"
}
)
指令given[math.random(#given)]
给你table。例如 given[1]
等于 {"What is the answer 1", answer = "17"}
。要获得唯一的问题,您需要使用方括号和索引。从 Understanding lua tables in corona sdk 阅读更多关于 table 的信息。