Page 1 of 1

Stop Timer

Posted: May 2nd, 2010, 8:46 pm
by Opel
Hey guys im wondering if it is possible to pause the timer i made so the person can see thier time when the press frag button. This is the code i use to destroy it so if it is possible how would i change it? If you dont get me here is a video. http://www.xfire.com/video/29ad18/

Code: Select all

TimerButtonstop()
{
       self endon("disconnect");
       self endon("killed_player");
       self endon("joined_spectators");

       for(;;)
       {
		if( self fragButtonPressed() && self isOnGround() )
		{
		     self thread removetimer();
                      wait 1;	
		}
		wait 0.05;
	}
}

removetimer()
{
	self endon("disconnect");
	self endon("killed_player");
	self endon("joined_spectators");
	
	self.timer destroy(); 
}


Re: Stop Timer

Posted: May 3rd, 2010, 2:33 am
by Drofder2004
where is the code for your timer?

All you are currently doing is destroying it (which looking at your code is going to cause "undefined object" errors.

Re: Stop Timer

Posted: May 3rd, 2010, 8:08 am
by Opel
here is the full script. some of it when out of line

Code: Select all


TimerButton()
{
       self endon("disconnect");
       self endon("killed_player");
       self endon("joined_spectators");
	
		check1 = false;

       for(;;)
       {
		if( self useButtonPressed() && self isOnGround() )
		{
			check1 = true;
			wait 0.5;
		}

		if( check1 && self attackButtonPressed() )
		{
		      self thread timerstart();
                      wait 1;	
			check1 = false;
		}
		wait 0.05;
		check1 = false;
	}
}

TimerButtonstop()
{
       self endon("disconnect");
       self endon("killed_player");
       self endon("joined_spectators");

       for(;;)
       {
		if( self fragButtonPressed() && self isOnGround() )
		{
		      self thread removetimer();
                      wait 1;	
		}
		wait 0.05;
	}
}

removetimer()
{
	self endon("disconnect");
	self endon("killed_player");
	self endon("joined_spectators");
	
	self.timer destroy(); 
}

timerstart()
{
		self endon("disconnect");
		self endon("killed_player");
		self endon("joined_spectators");
		self endon("stop_timer");

	self.timer = newHudElem(self);
	self.timer.alignX = "center";
	self.timer.alignY = "middle";
	self.timer.horzAlign = "center";
    self.timer.vertAlign = "top";
   	self.timer.y = 100;
  	self.timer.fontScale = 1.6;
	self.timer.color = (0.8, 1.0, 0.8);
	self.timer.font = "objective";
	self.timer.glowColor = (0.3, 0.6, 0.3);
	self.timer.glowAlpha = 1;
	//self.timer SetPulseFX( 30, 900000, 700 );//something, decay start, decay duration
 	self.timer.hidewheninmenu = true;
	self.timer.label = &"Time    ";
	self.timer SetTenthsTimerUp( 1 );
}
  

Re: Stop Timer

Posted: May 4th, 2010, 12:24 pm
by Drofder2004
I personally would change your method of doing it and creating your own timer.

Code: Select all

 self endon("end_time")
self.timer = 0;
time = 0.1;
while(1)
{
   wait time;
   self.timer += time;
} 
Use that is the value of a HUD element and then, when doing a 'self notify' you will stop the counter and the time will be kept on the elem until you destroy that.

Re: Stop Timer

Posted: May 10th, 2010, 4:07 pm
by Opel
Thanks mate. Just had time to try it and it works great