[HELP] Race Time Counter..
#1

hi,

I wanted to create a race time counter for my racing script (yrace, edit'd it for my script). But, it doesn't count the time exactly. Here're the codes:

Code:
.
.
.
	{
		format(ystring, sizeof(ystring), "~g~GO!",cd);

		RaceMiliSeconds = 0;
	    RaceSeconds = 0;
	    RaceMinutes = 0;
		RaceTimer = SetTimer( "RaceTimex", 10, 1);
.
.
.
The timer is;

Code:
public RaceTimex()
{
	RaceMiliSeconds++;
	if(RaceMiliSeconds == 100) //counts miliseconds, 100 milisecs = 1 sec
	{
	    RaceSeconds++;
	    RaceMiliSeconds = 0;
	}
	if(RaceSeconds == 60) //counts seconds, 60 secs = 1 min
	{
	    RaceMinutes++;
	    RaceSeconds = 0;
	}
}
The timer starts counting after race start countdown (3, 2, 1, and it starts with "GO!"). But when i finished the race, it doesn't give the time exactly. Can you see anything wrong here?
Reply
#2

What is wrong with the original yrace race time ?
Reply
#3

That's not the point, i just want to learn what's wrong with this script.
Reply
#4

Ok, just i got a fix for the yrace timer bug.
Reply
#5

yrace timer works quite cool. Please stay in topic, help me, or don't spam it anymore.
Reply
#6

EDIT: Nevermind.
Reply
#7

No. You're calling the timer every 10 milliseconds, while you increase the millisecond variable with just 1 (instead of 10) when it's called. There are also 1000 milliseconds in one second, not 100.
Reply
#8

you mean:

Code:
Settimer("RaceTimer", 1, 1);

public RaceTimex()
{
    RaceMiliSeconds++;
    if(RaceMiliSeconds == 1000)
    {
        RaceSeconds++;
        RaceMiliSeconds = 0;
    }
    if(RaceSeconds == 60) 
    {
        RaceMinutes++;
        RaceSeconds = 0;
    }
}
?
Reply
#9

Yes, that would work. But calling a timer every millisecond is not a very good practice. I was thinking more like:
pawn Code:
Settimer("RaceTimer", 100, 1);

public RaceTimex()
{
    RaceMiliSeconds += 100;
    if(RaceMiliSeconds == 1000)
    {
        RaceSeconds++;
        RaceMiliSeconds = 0;
    }
    if(RaceSeconds == 60)
    {
        RaceMinutes++;
        RaceSeconds = 0;
    }
}
This will still call the timer 10 times per second, which is too fast for the human eye to notice any difference.
Reply
#10

Oh, ur right. That may work, i'm going to try in mins. BRB
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)