Hi, I’m a beginning programmer and I feel like I’m not understanding something about the for statement or the use of the timer.performWithDelay. If I use the code below as it is, the final iteration (in this example the 5th) iteration of the for statement always bombs. I remove the closures for the objectmove function and the timer and all 5 iterations appear and function as expected. When introducing the timer and the closures however all but the final iteration behave as expected. The square in the final iteration never appears. I have some more elaborate code where I was able to confirm that this iteration is in fact triggering but never becomes visible with the timer implemented to stagger them. I’ve pounded my head against the wall for a month and can find nothing wrong with my code which may be causing this. Is this a limitation of the for statement or timer library? Also I am still currently using the trial version so my only other thought is that this is perhaps a deliberate limitation of the trial version. If it is the case that my code is good and that this is a deliberate limitation due to it being the trial version it would be great to know so that I can move on and get this closer to where I want it to be before subscribing. Kind of hoping to avoid paying for a subscription if I figure out that I’m just not gonna hack it as a coder… Badum dum… lol Thanks all for any help with this!
[lua] – Global Variables
halfW = display.viewableContentWidth / 2
halfH = display.viewableContentHeight / 2
– Group Variables
local group = display.newGroup()
– Insert and position Characters
for i = 1, 5 do
group:insert (display.newRect( 0, 0, 50, 50 ))
group[i].xScale = .07
group[i].yScale = .07
group[i].isVisible = false
group[i]:setReferencePoint ( display.BottomCenterReferencePoint )
group[i]:translate( halfW + math.random( -80, 80 ), halfH + math.random( -250, -250 ) )
local spawntimer = (i*500) + 500
– Move and Scale Characters/Trigger Animation
timer.performWithDelay( spawntimer , objectmove )
objectmove = function( event )
transition.to( group[i], { time=15000, x = math.random( 40, 500 ) } )
characterYGo = function( event )
group[i].isVisible = true
charYpos = group[i].y
group[i].y = charYpos * 1.002 + 0.5
ScalePercent = (group[i].y ) / 8 + 4
group[i].xScale = 0.015 * ScalePercent
group[i].yScale = 0.015 * ScalePercent
end
Runtime:addEventListener( “enterFrame”, characterYGo )
end
end [/lua]