[Resolved] How to cancel the following function

I am using a function that sets up a cloud table, and has clouds move down the screen. This function clouds is in an external module, and i am basing my work off of the “star” example.

I am trying to use director with my program, and when i change the scene, clouds continue to fall.

function Clouds ()  
  
 function moveGround()  
 moveTheGround = transition.to(ground, { delay = 0,  
 time= 6000,   
 y=\_H + 500  
 }) -- Move the Cloud  
 end  
  
  
 local cloudTable = {} -- Set up cloud table  
  
 function initCloud()  
 local cloud1 = {}  
 cloud1.imgpath = "cloud2.png"; --Set Image Path for cloud  
 cloud1.movementSpeed = (-jetpackNumber + 6) \* 500; --Determines the movement speed of cloud  
 table.insert(cloudTable, cloud1); --Insert Cloud into cloudTable  
  
 local cloud2 = {}  
 cloud2.imgpath = "cloud1.png";  
 cloud2.movementSpeed = (-jetpackNumber + 6) \* 500;  
 table.insert(cloudTable, cloud2);   
  
 local cloud3 = {}  
 cloud3.imgpath = "cloud1.png";  
 cloud3.movementSpeed = (-jetpackNumber + 6) \* 1000;  
 table.insert(cloudTable, cloud3);  
 end --END initCloud()   
  
 function getRandomCloud()  
 local temp = cloudTable[math.random(1, #cloudTable)] -- Get a random cloud from cloudTable  
 local randomCloud = display.newImage(temp.imgpath) -- Set image path for object  
 randomCloud.myName = "cloud" -- Set the name of the object to cloud  
 randomCloud.movementSpeed = temp.movementSpeed; -- Set how fast the object will move  
 randomCloud.x = math.random(0,\_W) -- Set starting point of cloud at a random X position  
 randomCloud.y = - 50 -- Start the cloud off screen  
  
 cloudMove = transition.to(randomCloud, {  
 time=randomCloud.movementSpeed,   
 y=\_H + 150,  
 onComplete = function(self) self.parent:remove(self); self = nil; end  
 }) -- Move the cloud  
 end--END getRandomCloud()  
  
 function startGame()  
  
 cloudTimer1 = timer.performWithDelay(1000,getRandomCloud, 0)  
 cloudTimer2 = timer.performWithDelay(1300,getRandomCloud, 0)  
 end--END startGame()  
  
  
  
 initCloud()  
 startGame()  
 moveGround()  
  
end  

Any one know what i am doing wrong?

Thanks [import]uid: 24708 topic_id: 24805 reply_id: 324805[/import]

Are you ending the cloud timer when you change scenes? [import]uid: 52491 topic_id: 24805 reply_id: 100773[/import]

I literally did that 5 times, and now i got it to work! I thought thats what you do but i guess i did that wrong.

Thank-you for your help!

I figured out what i was doing wrong. I was using a separate lua file to store the cloud function, the timer its self, was set to local. I am guessing that you cant access a local variable or local anything, when you are calling it from a different lua file?
Thanks again! [import]uid: 24708 topic_id: 24805 reply_id: 100784[/import]

That’s correct, you wouldn’t have been able to access it. (It would have printed a nil warning, I believe.)

Happy it’s sorted now, good luck with the rest of your project :slight_smile:

Peach [import]uid: 52491 topic_id: 24805 reply_id: 100948[/import]