所以这就是问题,我正在尝试使用lua数组在计算机技术中创建一个完全可自定义的UI,当我使用它时,ui似乎总是空的
function dupChar(char, num)
ret = ''
for ii=1,num do
ret = ret..char
end
return ret
end
function drawLoad()
--Pattern:
-- X, Y, Text, FG, BG, Disabled for op, button action
ui = {}
ui.hungerStart = {3,4,'[',nil,nil,false,'none'}
ui.hungerMid1 = {ui.hungerStart[1] + 1,ui.hungerStart[2],dupChar('-',20),nil,nil,false,'none'}
ui.hungerMid2 = {ui.hungerStart[1] + 1,ui.hungerStart[2],hunger,nil,nil,false,'none'}
ui.hungerStop = {ui.hungerStart[1] + 21,ui.hungerStart[2],']',nil,nil,false,'none'}
ui.healthStart = {3,6,'[',nil,nil,false,'kill'}
ui.healthMid1 = {ui.healthStart[1] + 1,ui.healthStart[2],dupChar('-',20),nil,nil,false,'health'}
ui.healthMid2 = {ui.healthStart[1] + 1,ui.healthStart[2],health,nil,nil,false,'health'}
ui.healthStop = {ui.healthStart[1] + 21, ui.healthStart[2],']',nil,nil,false,'heal'}
end
function drawAdv(pName, page)
isOp = false
pHealth = 10
pHunger = 10
health = dupChar('$',pHealth)
hunger = dupChar('@',pHunger)
drawLoad()
color(custCol.default[1], custCol.default[2])
stat.clear()
term.clear()
for index, value in ipairs(ui) do
x, y, text, fg, bg, disOp, action = value[1],value[2],value[3],value[3],value[4],value[5],value[6]
color(custCol.default[1], custCol.default[2])
cur(x,y)
if disOp then
color(custCol.disOp[1], custCol.disOp[2])
else
color(fg,bg)
end
awrite(text)
end
end
另一件事是知道是否
for index, x, y, text, fg, bg, disOp, action in ipairs(ui) do
或
for index, value in ipairs(ui) do
x, y, text, fg, bg, disOp, action = value[1],value[2],value[3],value[3],value[4],value[5],value[6]
是获取列表条目的方式
注意:代码有点乱,但这是因为我试图尽可能在不使用ComputerCraft的情况下使用它(有些功能仍在这里,但不能用于lua)感谢您阅读并可能帮助我:)
答案 0 :(得分:1)
for index, value in ipairs(ui) do
local x, y, text, fg, bg, disOp, action = unpack(value)
-- do something
end
function dupChar(char, num)
return char:rep(num)
end