Game Development Community

timer reward system

by rennie moffat · in Torque Game Builder · 04/06/2010 (8:26 am) · 6 replies

Hi I have developed a timer reward system, being that if my player touches the reward he has time deducted from the timer.. a good thing. The thing is that when I set the reward value to say 1, the clock is set back approximately 8 seconds. When I set it to say 3 it is set back about 24, @ 7 it is set back about 60.

I placed echos inside my relevant functions and studies what was happening. The thing that puzzles me is that onCollision, when player touches the reward the clock is not set back from say 33 to 25 instantly, but that it goes down intermittently from 33, 32, 31, and so on until it reaches 25. Why would it not just jump back to the appropriate frame number? And why does it jump back to numbers which are not the expected value?







///part of the reward behavior
function reward2::giveToTemple(%this)
{
	%bouncer = %this.bouncer.getBehavior("timerBehavior");
	if(!isObject(%bouncer))
	return;
	
	$currentTimeSeconds -= %this.timeValue;
	%bouncer.updateSeconds();
}


////part of the timer behavior
function timerBehavior::updateSeconds(%this)
{
	%this.seconds.setFrame($currentTimeSeconds);	
}



of note, if the jump back exceeds 0, there is a delay in when the clock resets. as in, if say the jump is a value of 20, but the clock is at 15 when the jump occurs a 5 second delay occurs until the clock is started again.

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
04/06/2010 (9:53 am)
line 8 -= is why it is decrementing you need to set up globals for different reward types add a switch for the reward being gotten then += seconds to add
#2
04/06/2010 (10:31 am)
It is decrementing because I want to lower the time as a reward.

I had the reward type (length of time bonus) as simply a behavior field thinking the behavior would handle it and I could then use that behavior numerous times, adjusting the reward value thruout the game.



If anyone has a clearer insight into why I am seeing a random jump in the int value applied, please answer. Thanks.

And thanks, too michael.
#3
04/06/2010 (11:46 am)
Ren,

It seems like the code above is functioning as expected but it's being called multiple times as the collision is fired multiple times when the player stays in contact with the object he is colliding with for a brief moment.

You can turn off collisions on the object being collided with then reactivate collision via a schedule to make sure the collision callback doesn't get repeatedly fired.

`Patrick
#4
04/06/2010 (12:08 pm)
after you explained it more patrick is more on the dot. but this fuctionality my self in design would not use a behavior
#5
04/06/2010 (12:24 pm)
right,

good thought Patrick,
Thanks!!!!
#6
04/16/2010 (1:14 pm)
uh uh uh excellent.