Runtime Timers

Game Editor comments and discussion.

Runtime Timers

Postby joncb » Tue Mar 06, 2012 4:34 am

I can create a time in Runtime using CREATETIMER. Can I create a timer event handler in runtime?

The reason I am asking is that I need to create a timer after a certain event (Collision). The collision actor is destroyed, however, there needs to be a dedicated timer associated with that particular collision event. Normally not an issue, however, there are clones of the collision actor, which can also have a collision event - spawning new timers, which may occur before the original timer expires.

I don't want to be limited to a prescribed number of collision actors, give them individual names then create a whole lot of timer events attached to the event actor; as for different levels in the game there is going to be a different number of collision actors.

The specific case is when a ball hits a specific actor, the ball shrinks (say to size 2) for a prescribed period of time - before it returns to its original size (size 1). If the ball collides with a clone of the collision actor before the fist timer expires, the ball will shrink further (to size 3) - initating a second time - and so on. Once the first time expires, the ball will grow back to size 2, and once the second time expires, the ball returns to size 1. This is in effect a recusrsive algorithm, which I am not sure gE can accomodate, so is there a work around?

My approach is to create a timer on the collision event with a specific name based on the number of the clone. When that time event occurs, grow the ball up to the next size (managed through a global variable), then destroy the timer. But I need to create a timer event handler for the timer of that specified name.

clear as mud??

any suggestions welcome.

joncb
joncb
 
Posts: 10
Joined: Sat Mar 03, 2012 1:54 am
Score: 0 Give a positive score

Re: Runtime Timers

Postby skydereign » Tue Mar 06, 2012 6:33 am

Quick answer, you can't create new timer types. A cool idea though. What I'd recommend is creating your own timer system. Namely you would store timers in a global place, and create them as you need them. The simplest way would be to use several arrays. Each sub of the array stands for a different timer, and in say the view's draw actor, it reduces all the timers by 1 (assuming they are active [timer>0]). Then it sends an activation event to the actor that the timer should 'belong' to. To do this you'd also have to store the clonename of the actor you want to create the timer for.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Runtime Timers

Postby joncb » Tue Mar 06, 2012 10:58 am

Thanks Sky. I was hopefull. My fallback approach isn't a lot different to yours +1
joncb
 
Posts: 10
Joined: Sat Mar 03, 2012 1:54 am
Score: 0 Give a positive score

Re: Runtime Timers

Postby skydereign » Tue Mar 06, 2012 6:23 pm

Oh? It sounded like you were going to create a bunch of actual timers, essentially one for each clone. Which is fine I guess, but with the activation event, and use of a global timer bank, you can use a single event to handle the timing, and another to handle the trigger, where I believe you'll have to create a new timer event for each one if you use actual timers. That is if I understood you right.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Runtime Timers

Postby joncb » Wed Mar 07, 2012 10:41 am

I realised that the multiple timer approach was not going to be practicle and provide the flexibility I need. I have it working by creating a timer that lasts for 1 sec. When the timer goes off I check an decrement the value in the array, and once the value in the array reaches 0 I then execute the necessary command.

The 1 sec timer will be useful for other funtions in the program I suspect.

thanks again

joncb
joncb
 
Posts: 10
Joined: Sat Mar 03, 2012 1:54 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest