1

I currently have a bunch of boxes that look similar to

<Texture name="uiBox01">
    *Other content*
</Texture>

This continues for 18 boxes (uiBox18). In Lua I am capable of referencing the boss and changing its color via

uiBox01:SetVertexColor(r,g,b)

The problem is I may or may not need more boxes for an operation. The given operation could utilize 2 boxes on its first pass and maybe 8 on the next. As such it needs to be dynamic instead of static.

Ultimately I would like to use an array with Lua such that

uiBox[1] = uiBox01 --something similar to this

so that I can specify the next index more efficiently. Any help would be much appreciated!

EDIT: The XML used is WoW UI XML it's very similar to basic XML.

4

1 回答 1

0

我不确定你的问题是否正确。我假设您想要做的是能够使用数组中的索引而不是变量名来引用一个框。

i=5  -- set from somewhere,maybe a loop
-- after some time
myBox = boxes[i]

我对 WoW 不熟悉,但我认为 uiBox01 是由 WoW 以某种方式创建的全局变量。

在 Lua 中,全局变量存储在 _G 数组中,index 是变量的名称。所以

uiBox01 == _G['uiBox01']  -- returns true

所以以下必须为你工作

i=5  -- set from somewhere,maybe a loop
-- after some time
myBox = _G['uiBox'..i]

如果 i 是单个数字,则扩展它以处理前缀零

i=5  -- set from somewhere,maybe a loop
-- after some time
myBox = _G['uiBox'.. (i < 10 and '0' or '' ) .. i] -- concatenate zero in middle if i<10

如果您正在寻找其他东西,请告诉我。

于 2013-09-12T06:30:51.750 回答