using onTimeChange instead of an Timer with infinite time

Started by MacTavish, Dec 26, 2015, 02:06 PM

Previous topic - Next topic

MacTavish

Q: is it good to use onTimeChange instead of an infinite timer for some function such as savestatsall(a function that save the stats of all players)?

I made something through onTimeChange and it works. Let me show what i made.

function onScriptLoad()
{
InfiniteTimer <-0;
InfiniteTimer = time() + 14; // just example i wrote on mobile but exact code is in pc so
}

function onTimeChange(oldHour, oldMin, newHour, newMin)
{
if ( time() > InfiniteTimer && InfiniteTimer !=null)
{
print(" we passed 15 secs and it works ");
// there we can use our function but for example i am using print and it prints after every 15secs
// to avoid repeating we can set InfiniteTimer = null  here

// to repeat we can set more time
// InfiniteTimer = time()+14;
}
}
Now please answer my question :)

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

oh no

.

Use timer and save your self a couple Squirrel function calls that aren't necessary. This is an incorrect use of this function.
.

DizzasTeR

Timers are not bad, and why would you need a timer to save stats in the first place? Just save them when a player leaves.

"Omg dude my server can crash what about that!"

Create stable scripts which cannot crash as simple as that. Losing 20 - 30 kills won't matter anyway if it crashes, vcmp nerds can obtain them again.

MacTavish

Sorry forgot something to add now updated

Please guys look it once more
@KAKAN @S.L.C


Quote from: Doom_Kill3R on Dec 26, 2015, 02:33 PMTimers are not bad, and why would you need a timer to save stats in the first place? Just save them when a player leaves.

"Omg dude my server can crash what about that!"

Create stable scripts which cannot crash as simple as that. Losing 20 - 30 kills won't matter anyway if it crashes, vcmp nerds can obtain them again.

I agree but what about some other stuff thus need an infinite timer or a timer with 20secs

Don't get me wrong this is just an idea

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

DizzasTeR

Small stuff which need infinite timers aren't that bad just never ever run queries in timers, for example running queries on a timer of less than 20 minutes will cause lags.

MacTavish


Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P