如何在Lua中存储特定值并检索连接?
我有四个功能。 每个函数的执行时间。 它将在表中存储一些不同的值。 当执行Enter函数时,它将检索。 逐一地。 表中存储的任何函数数据如何在Lua中存储特定值并检索连接?,lua,Lua,我有四个功能。 每个函数的执行时间。 它将在表中存储一些不同的值。 当执行Enter函数时,它将检索。 逐一地。 表中存储的任何函数数据 table={} function one() table.one="1" end function two() table.two="2" end function three() table.three="3" end function four() table.four="4" end function en
table={}
function one()
table.one="1"
end
function two()
table.two="2"
end
function three()
table.three="3"
end
function four()
table.four="4"
end
function enter()
for i,v in pairs(table)do
print("on by one",v)
end
end
one()
two()
enter()
输出:1 2它是一个接一个的顺序
我想要这样的输出:12
如果我下次执行函数的顺序不同,那么
two()
one()
enter()
输出:2 1它是一个接一个的顺序
我想要这样的输出:21
如果我下次执行
two()
three()
four()
enter()
我想要这样的输出234
这是否可以编写代码。
请帮助任何人首先,覆盖表不是一个好主意 如果您对以特定顺序获取表元素感兴趣,则不应使用pairs迭代器,因为它使用next以未指定的顺序枚举表键
local digits = {}
function one()
table.insert(digits, 1)
end
function enter()
print(table.concat(digits))
digits = {}
end
请注意,这仅适用于字符串或数字值。请正确设置问题/代码的格式问题更容易混淆请编辑您的问题并清楚地说明您的问题