Confused (timers)

Have questions about CoD2 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Confused (timers)

Post by Rezil » June 5th, 2010, 4:50 pm

I have made a simple timer which does what it's supposed to but the problem is that it's going too fast. The (relevant) code is this:

Code: Select all

make_stopwatch()
{

	self.stopwatch  = newclienthudelem(self);
	self.stopwatch .x = 630;
	self.stopwatch .y = 65;
	self.stopwatch .alignX = "right";
	self.stopwatch .alignY = "bottom";
	self.stopwatch .font = "default"; 
	self.stopwatch .fontScale = 1.3;	
	self.stopwatch .archived = false;
	self.stopwatch .color = (1, 1, 1);
	self.stopwatch  setvalue(self.time );
}
simple_stopwatch()

{

	t = getent("test5","targetname");
	
	while(1)
	
	{
	
		t waittill("trigger", user);
		if(!isdefined(user.time))
		{
			user.time = 60;
		}
		user make_stopwatch();
		for(i=60;i>0;i--)
		{
			user.time--;
			user.stopwatch setvalue(user.time);
			wait 1;
		}

	}
}
Found out about settimer but it's only accurate to a second(I want tenths of a second aswell - want to buid my own timer from scratch for practice). I thought wait 1; waits for 1 second but my timer and the one in the top left corner don't count down the same, mine is faster. :/

Any ideas how to make it work for exactly 1 second? (I might be totally wrong about wait 1; aswell)
Last edited by Rezil on June 5th, 2010, 4:55 pm, edited 1 time in total.
Reason: more info
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Confused (timers)

Post by Drofder2004 » June 5th, 2010, 5:43 pm

Code: Select all

simple_stopwatch()
{
	t = getent("test5","targetname");
	
	while(1)
	{
            t waittill("trigger", user);
            if(!isdefined(user.time))
               user thread make_stopwatch(60);
	}
}

make_stopwatch(time)
{
   self.stopwatch = newclienthudelem(self);
   self.stopwatch.x = 630;
   self.stopwatch.y = 65;
   self.stopwatch.alignX = "right";
   self.stopwatch.alignY = "bottom";
   self.stopwatch.font = "default";
   self.stopwatch.fontScale = 1.3;   
   self.stopwatch.archived = false;
   self.stopwatch.color = (1, 1, 1);

   for(i=0;i<time;i+=0.1)
   {
      self.time = i;
      self.stopwatch setValue(self.time);
      wait 0.1;
   }

   self.time = undefined;
   self.stopwatch destroy();
}
try.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 5:58 pm

Works great but I lol'd a bit at the results:

Sometimes it's skips/approximates the time to x.9999 or x.0001, other times it stays fine for 20 or so seconds. I had a time of 32.9997 IIRC. The same problem persists however: it goes too fast. Either the ingame timer is slower or the wait command is not exactly 1 second(which I'm pretty sure it is).
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Soviet
Core Staff
Core Staff
Posts: 7760
Joined: April 23rd, 2005, 9:12 pm
Location: Plano, Texas
Contact:

Re: Confused (timers)

Post by Soviet » June 5th, 2010, 6:37 pm

to solve the decimal issue:

Code: Select all

temp = Int(self.time);
self.stopwatch setValue(temp);
Image
ImageImageImage
Image
"Zaitsev is a cunt." - Pedsdude

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 6:44 pm

Nope, it makes the number an integer, but I want it aproximated to 1/10.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Soviet
Core Staff
Core Staff
Posts: 7760
Joined: April 23rd, 2005, 9:12 pm
Location: Plano, Texas
Contact:

Re: Confused (timers)

Post by Soviet » June 5th, 2010, 6:47 pm

Ah, well I know how you could handle that in Java, but I'm pretty sure Q3 scripting isn't complex enough. It would involve typecasting the int as a string then splitting it at the decimal point, keeping one digit after the decimal and merging it back together. Unfortunately Q3 scripting just doesn't have the methods required. I suppose you'll have to focus on the more fundamental issue and hopefully that will solve itself.
Image
ImageImageImage
Image
"Zaitsev is a cunt." - Pedsdude

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 6:50 pm

I figured as much, I can make it simulate a .1 accuracy by looping the value of a sperate HUD element from 9 to 0 and putting it next to the seconds one but it's a lame workaround and I want it to be exact and stored as a single variable.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: Confused (timers)

Post by waywaaaard » June 5th, 2010, 6:53 pm

a getSystemTimeInMilliseconds function would be great :P
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Confused (timers)

Post by Drofder2004 » June 5th, 2010, 7:49 pm

CoD Script wait is EXACT, unless your game is set incorrectly...

If I do:

Code: Select all

for(i=0;i<10;i+=0.1)
{
   iprintln(i);
   wait 0.1;
}
I get perfect numbers...

The only thing you must abide to is a 1/20 time limit (0.05 seconds minimum wait time)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 7:52 pm

Well try using the script you posted, if you indeed get all perfect numbers then it might be something wrong with my game...
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Confused (timers)

Post by Drofder2004 » June 5th, 2010, 8:45 pm

ok, you were right... simple fix.

Code: Select all

   time = time * 10;

   for(i=0;i<time;i++)
   {
      self.time = i / 10;

      self.stopwatch setValue(self.time);
      wait 0.1;
   }
USe that instead of the current for loop.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 10:05 pm

Code: Select all

simple_stopwatch()
{
   t = getent("test5","targetname");
   
   while(1)
   {
            t waittill("trigger", user);
            if((!isdefined(user.secondtime)) && (!isdefined(user.minutetime)))
               user thread make_secondswatch();
			   user thread make_minuteswatch();
			   user thread dots_inbetween();
   }
}

make_secondswatch()
{
   self.secondwatch = newclienthudelem(self);
   self.secondwatch.x = 322; //max 650
   self.secondwatch.y = 450; //max 475
   self.secondwatch.alignX = "left";
   self.secondwatch.alignY = "bottom";
   self.secondwatch.font = "default";
   self.secondwatch.fontScale = 2;   
   self.secondwatch.archived = false;
   self.secondwatch.color = (1, 1, 1);
   for(;;)
   {
		secondtime = 0;
		secondtime = secondtime * 10;
		seconds = 0;
		for(i=seconds;i<=599;i++)
		{
		  self.secondtime = i / 10;
		  self.secondwatch setValue(self.secondtime);
		  wait 0.1;
		}
		wait 0.05;
	}
}

make_minuteswatch()
{
   self.minutewatch = newclienthudelem(self);
   self.minutewatch.x = 311; //max 650
   self.minutewatch.y = 450; //max 475
   self.minutewatch.alignX = "right";
   self.minutewatch.alignY = "bottom";
   self.minutewatch.font = "default";
   self.minutewatch.fontScale = 2;   
   self.minutewatch.archived = false;
   self.minutewatch.color = (1, 1, 1);
	self.minutetime = 0;
    minutes = 0; //And no I don't know why I used this instead of just putting i=0;
    for(i=minutes;i>=0;i++)
    {
      self.minutewatch setValue(self.minutetime);
	  if(self.secondtime == 599/10) self.minutetime++;
	  wait 0.1;
    }
}

dots_inbetween()
{
	self.dots = newclienthudelem(self);
	self.dots.x = 318; //max 650
	self.dots.y = 450; //max 475
	self.dots.alignX = "right";
	self.dots.alignY = "bottom";
	self.dots.font = "default";
	self.dots.fontScale = 2;   
	self.dots.archived = false;
	self.dots.color = (1, 1, 1);
	for(;;)
	{
		self.dots.label = &":";
		wait 0.7;
		self.dots.label = &" ";
		wait 0.7;
	}
}
Image

Hooray, it works nicely. Thanks for your help Drof. :)

edit: One last thing, I've noticed that there will be an accumulation of 0.05 seconds error for every minute. Any way to fix it?(I want the seconds timer to loop from 0 to 59.9 indefinitely but I see no other way than with another for loop).
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Confused (timers)

Post by Drofder2004 » June 5th, 2010, 10:17 pm

Code: Select all

for(i=minutes;i>=0;i++)
Thats an infinite loop...

If you dont want the for loop to end just do

Code: Select all

for(;;)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Confused (timers)

Post by Rezil » June 5th, 2010, 10:22 pm

Right but a for loop requires a wait statement. Any other way to loop forever without waiting?
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Confused (timers)

Post by Drofder2004 » June 5th, 2010, 11:12 pm

All loops must have a definite end or a wait statement. Otherwise, it is infinite...
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests