RESOLVED: syntax question: array notation similar to ActionScript?

I have 4 similar objects firing:

seaSpriteInstance1:play()
seaSpriteInstance2:play()
seaSpriteInstance3:play()
seaSpriteInstance4:play()

what is the correct for loop syntax that would do the same thing?
In AS3, it would look something like:

for(var i:Number = 1; i<5; i++){
this[‘seaSpriteInstance’+i].play()
}

Thanks! [import]uid: 146743 topic_id: 27120 reply_id: 327120[/import]

Are your sprites in a table? If not, create one;
[lua]local seaSprite = {}[/lua]

Insert your sprites;
[lua]table.insert(seaSprite, seaSpriteInstance1)[/lua]

Then do a for loop like so;
[lua]for i = 1, 4 do
seaSprite[i]:play()
end[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 27120 reply_id: 110089[/import]

Or like so (there are several different ways you can structure this):

local mySprites = {
sprite = nil, anim = “jump”,
sprite = nil, anim = “walk”,
sprite = nil, anim = “run”,
sprite = nil anim = “climb”,
end

for i = 1, #mySprites do
mySprites[i].sprite = sprite.newSprite(spriteSet)
mySprites[i]:prepare(mySprites[i].anim)
mySprites[i]:play()
end [import]uid: 84637 topic_id: 27120 reply_id: 110123[/import]

hey guys, thanks for the responses! [import]uid: 146743 topic_id: 27120 reply_id: 110183[/import]