Repeating "game timer"... good or bad idea?

My current Lua program features a “game timer” which functions exactly as I want it to, but I’m not sure it’s practical. Basically, this timer resides near the end of my code, by itself and outside a function, and it currently executes every 1/2 second. When it executes, the related Listener function performs some other code.

Here’s the reason for all of this: I want to randomly move a series of objects around the screen. References to these objects reside in a basic table (simple key-value array) and when the game timer executes, it loops through this list and modifies/updates each object’s movement angle. This results in a random movement of all objects. Later, I intend to use this game timer for other purposes, i.e. setting some objects to “hunt” other objects by locking on to that target and effectively following it (every 1/2 second, according to the game timer) until presumably they collide.

My initial approach to this issue, a few days ago, was to “attach” an individual timer to each object and execute them repeatedly. Not only did this approach seem unreliable, but I felt that 1 master game timer looping over 20+ objects would be far faster and cleaner than 20+ individual timers executing on a per-object basis.

So does my “game timer” approach seem practical? Will the entire game become sluggish if the Listener function is looping over 20-30 objects, or can Corona handle that load fairly easily? Does anybody have an alternative suggestion to this entire scenario?

Thanks as always,
Brent
[import]uid: 9747 topic_id: 2701 reply_id: 302701[/import]

Yes. That’s who I would set it up given what you have described.

Or, you could do something like:

  
local function myFunctionCall (event)  
  
 -- in here the other alternative would be to check the time  
  
 getTime() -- not a real function... just using pseudo code  
 compare the time against a previous time and see if enough time has passed to execute some code or return until there is a noticeable time difference  
  
 if the difference in time is greater than the time desired do   
 animateObjects  
 end  
  
 return  
  
end  
  
RunTime:addEventListner("enterFrame",myFunctioncall)  

Does this help?

carlos

[/code] [import]uid: 24 topic_id: 2701 reply_id: 7976[/import]