declaration of variables in cycle

Hello…
since I can hardly declare… I’d like to know if there is a multiply declaration of variables i.e. in the cycle. It will save my time and lines :slight_smile:
Is there some alternative to this model(doesn? work of course :))

for i=1,14 do local variab..i=movieclip.newAnim{"pic1.png","pic2.png"}; myGroup:insert(variab..i); variab..i.x=200; variab..i.y=200+(i-1)\*40; end

is there some syntax which I can use instead of that “variab…i” or I have to declare variables one by one?
thx for answers… [import]uid: 6869 topic_id: 1137 reply_id: 301137[/import]

Hi,

your declaration won’t work. But as you have declared your variables inside the loop as local, you won’t see them outside the for loop anyway. I recomment to study LUA’s scoping rules.

So, if you don’t need to see the variables outside the loop, then just reuse one:

[lua]for i=1,14 do
local variab=movieclip.newAnim{“pic1.png”,“pic2.png”};
myGroup:insert(variab);
variab.x=200;
variab.y=200+(i-1)*40;
end[/lua]

Later you can get access to each movieclip by indexing the group:

[lua]for i=1,#myGroup do
myMC = myGroup[i]
myMC:play()
end[/lua]

Or if you need to have access to the single variables somehow, then use a table (which a group is too):

[lua]local myTable = {}
for i=1,14 do
myTable[i]=movieclip.newAnim{“pic1.png”,“pic2.png”};
myGroup:insert(myTable[i]);
myTable[i].x=200;
myTable[i].y=200+(i-1)*40;
end

for i=1,#myTable do
myMC = myTable[i]
myMC:play()
end[/lua]

Cheers
Michael Hartlef

http://www.whiteskygames.com
http://www.twitter.com/mhartlef
[import]uid: 5712 topic_id: 1137 reply_id: 2915[/import]

THX Mike… it works properly :slight_smile:
Sumeragi [import]uid: 6869 topic_id: 1137 reply_id: 2945[/import]