Page 1 of 1

cant call timer multiple times

Posted: Fri Jun 24, 2011 4:59 pm
by Paradan
i hope this isnt too confusing...

what im trying to do:
when a player engages an enemy they "dock" and pivot around a common point, but when the player pushes forwards(w) its rolls a movement attack, like pressing your enemy. if its successful it should push both of you along for a couple of meters. doing this uses some of your "action points", these points are refreshed every 2 seconds. also, your only allowed to do a push attack, once every second.

so far so good:
i have a round counter that flips back and forth between 0 and 1, i also have a toggle switch that gets flipped when you first hit the forwards key during that half-turn(one second). if the round counter and the push toggle arent equal, it wont do the push attack. every time the round counter flips over, it reinitializes the push toggle to an equivalent value. as far as i can tell, this is working just fine.

my problem:
in order to generate the movement Im calling a timer component, and having it do a velocity change everyframe/update. the timer interval and repeat amount get set based off of app.deltatime when you press the key. this also works, but it only works once, and then it quits working.
(it used to work 2 or 3 times, but only in a row, and then it quit working. i changed something while debugging)

ive traced my toggle switches and theyre all doing what they should be.

any ideas?

Posted: Sat Jun 25, 2011 12:58 pm
by VilleK
The way the Timer works is that if it reaches its RepeatCount it will not start again, even if you later update the RepeatCount to a higher value. I'm guessing this is what happens in your case since you write that you manipulate the RepeatCount.

So my advice would be to use another variable that flags whether the Timer should perform what it's doing, test this variable in a zexpression in timer Execute, and keep RepeatCount set to -1 so it won't stop.

Posted: Sun Jun 26, 2011 3:39 am
by Paradan
thank you, i got it working :D

i put the timer (with timer.repeatcount set to -1) under a condition in update, had the timer decrement the reps variable and toggle the conditions variable off when reps hit zero.

this mechanic now works as envisioned, thanks again.