Efficiency of timers
#1

Hey all,
While writing a script it's important for me to make it as efficient as I can do it.
So I taught about what would be better:
For example(!), I have a timer which repeats every second and checks for cheats. Furthermore the players speed (in vehicle) should be updated every second (speedometer) and a clock every 60 seconds.
So we have two functions which runs all the time (cheat-detector and clock-updater) and one which actually only have to run if the player is in a vehicle. Cheat-Detector and speedometer with the same interval and the clock * 60
What would be the best way to do it?
1. A seperate timer for each function (and each player who enters a vehicle)
2. Speedometer together with cheatfunction (for -> if in vehicle)
3. All together (2. + if sec == 60 do min++)

I don't exactly know how timers work so I ask for your knowledge

Phoenix
Reply
#2

I'd use seperate timers and stagger them. Its not timers that are inefficient its what people put inside them that is. You should set the players speedo timer when they enter a vehicle with SetTimerEx.
Reply
#3

Do timers anyway need computing power while they are not running? (Something like the server checks every second if a task has to be executed either way)
Reply
#4

I'm not sure how it works internally but, generally a CPU can process many "ifs" per millisecond (depending on what it is checking ofc) so i can't see it being inefficient. I'm no expert on efficiency But thats what i gather. In a mode i'm writting every player has their own update timer, so i don't have to use one timer that loops through all players saving their stats. (maybe causing lag spikes)
Reply
#5

Ok, thanks a lot, iggy1

(If anyone knows exactly how it works I would be still interested )
Reply
#6

If you have a lot of code inside them then you should keep them separate. But if its only few lines in timers that collide, you should combine them.
Reply
#7

Thanks but now I'm not really smarter.
WHY?

(So only one user-unspecific timer for a speedometer?)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)