Error when changing scenes

SOLVED

Hi all,

I have a scene with a bunch of clouds in it and I’m moving all the clouds at the same time. When I try to change my scene, I’m getting this error: ‘for’ limit must be a number.

Here is the chunk of code that’s causing the problems.

function moveClouds() for i=1, cloudGroup.numChildren do if ((cloudGroup[i]).x) \> display.contentWidth + 410 then (cloudGroup[i]).x = -410 (cloudGroup[i]).y = math.random( display.contentHeight \* 0.05, display.contentHeight \* 0.45 ) else (cloudGroup[i]).x = (cloudGroup[i]).x + 0.2 end end end

Any help is appreciated.

Anyone?

Well the error would imply that cloudGroup.numChildren isn’t a number.  Maybe you could do:  print(type(cloudGroup.numChildren)) and see what it says.  I suspect it’s nil and would want to ask, is cloudGroup in scope at that point?

My guess is that you are calling the cloud move function via a runtime listener but are not removing that listener when changing scenes.

@Rob, That was my first guess and the only real solution I found from researching. But it still had the same error when I put a number in there to test.

@Gremlin, That was it! Thank you!

Are you calling “moveClouds” function in timer.perform something?

Used timer to move clouds?

@felagund18, I was not using a timer to move the clouds. Instead, I was using a runtime listener to move the clouds every frame. Like this:

Runtime:addEventListener("enterFrame", moveClouds)

This checks the position of the clouds every frame and moves them accordingly.

Anyone?

Well the error would imply that cloudGroup.numChildren isn’t a number.  Maybe you could do:  print(type(cloudGroup.numChildren)) and see what it says.  I suspect it’s nil and would want to ask, is cloudGroup in scope at that point?

My guess is that you are calling the cloud move function via a runtime listener but are not removing that listener when changing scenes.

@Rob, That was my first guess and the only real solution I found from researching. But it still had the same error when I put a number in there to test.

@Gremlin, That was it! Thank you!

Are you calling “moveClouds” function in timer.perform something?

Used timer to move clouds?

@felagund18, I was not using a timer to move the clouds. Instead, I was using a runtime listener to move the clouds every frame. Like this:

Runtime:addEventListener("enterFrame", moveClouds)

This checks the position of the clouds every frame and moves them accordingly.