SA-MP Forums Archive
GetTimer or GlobalTimer? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetTimer or GlobalTimer? (/showthread.php?tid=472091)



GetTimer or GlobalTimer? - Patrick - 26.10.2013

Hello, Guys I'd like to ask you a question, which of this code is more optimized and faster?, Example code will be written below, I need your comments guys which of these techniques is much better and faster

pawn Код:
//This process will be repeated alot of time, (like 60 codes/function with this)
CMD:Hi(playerid, params[])
{
    new
        DelayTime[MAX_PLAYERS];

    if((gettime() - DelayTime[playerid]) < 60)
        return SendClientMessage(playerid, -1, "Please Wait.")

    DelayTime[playerid] = gettime();
    return 1;
}
Or

pawn Код:
//This process will be repeated alot of time, (like 60 codes/function with this
public OnGameModeInit();
{
    SetTimer("@GlobalTimer", 1000, true);
    return 1;
}

//Global Variable
new
    DelayTime[MAX_PLAYERS];

CMD:hi(playerid, params[])
{
    if(DelayTime[playerid] >= 1)
        return SendClientMessage(playerid, -1, "Please Wait.")

    DelayTime[playerid] = 60;
    return 1;
}

forward @GlobalTimer(); public @GlobalTimer()
{
    if(DelayTime[playerid] >= 1)
        return DelayTime[playerid] --;
    if(DelayTime[playerid]) <= 1)
        return DelayTime[playerid] =0;
    return 1;
}
Just wanted to know which method is much faster.



AW: GetTimer or GlobalTimer? - Mellnik - 26.10.2013

The first one but you won't feel a difference.


Re: AW: GetTimer or GlobalTimer? - Patrick - 26.10.2013

Quote:
Originally Posted by Mellnik
Посмотреть сообщение
The first one but you won't feel a difference.

Alright, It won't cause lag or something if used more than 60 times? I'm just confirming because one time I used [b]too much GetTickCount lags my server



Re: GetTimer or GlobalTimer? - unSatisfied - 26.10.2013

It doesn't matter, both are good.


Re: GetTimer or GlobalTimer? - Pottus - 26.10.2013

Always avoid timers whenever possible.


AW: GetTimer or GlobalTimer? - Mellnik - 26.10.2013

60 times a what? Its a normal native function which runs at c++ speed


Re: GetTimer or GlobalTimer? - Patrick - 26.10.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Always avoid timers whenever possible.
Thanks, so you're saying that I should use gettime(), instead of a timer.


AW: GetTimer or GlobalTimer? - Mellnik - 26.10.2013

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Thanks, so you're saying that I should use gettime(), instead of a timer.
Yeah right thats what he's sayin


Re: GetTimer or GlobalTimer? - -Prodigy- - 26.10.2013

Yeah, don't use timers for this kind of things.. also, what's with people using "@" in their functions? Looks pretty daem ugly imo


Re: GetTimer or GlobalTimer? - Patrick - 26.10.2013

Quote:
Originally Posted by Mellnik
Посмотреть сообщение
60 times a what? Its a normal native function which runs at c++ speed
I mean like I'll use this method more or less than 60 times.

Quote:
Originally Posted by -Prodigy-
Посмотреть сообщение
Yeah, don't use timers for this kind of things.. also, what's with people using "@" in their functions? Looks pretty daem ugly imo
It's a style