Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] Best practice with timers

 
  • 0 Vote(s) - 0 Average
Pawn Best practice with timers
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#1
2021-01-21, 02:16 AM (This post was last modified: 2021-01-21, 02:19 AM by RhaegarX.)
Hello guys!  I would like to ask a question about the use of timers.  Suppose I have several systems that do checks from time to time, the best way would be to create a single timer that does all the checks or create multiple timers to check each thing?  Which way would be the most optimized and least burdensome on the server?

Code 1:
PHP Code:
SetTimer("ExecuteAll", 1000, false);

public 
ExecuteAll()
{
    
// Verification 1
    // Verification 2
    // Verification 3
    
...
} 

Code 2:

PHP Code:
SetTimer("Execute1", 1000, false);
SetTimer("Execute2", 1000, false);
SetTimer("Execute3", 1000, false);

public 
Execute1()
{
    
// Verification 1
}
public 
Execute2()
{
    
// Verification 2
}
public 
Execute3()
{
    
// Verification 3
} 
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#2
2021-01-21, 09:57 AM
Just don't have more than 50.000 running timers at the same time and everything will be fine, it's case to case dependant so I can't really tell what's better
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
Freaksken
Offline

open.mp Developer

Posts: 80
Threads: 4
Joined: Feb 2019
Reputation: 6
Location: Belgium
#3
2021-01-21, 05:49 PM
Y_Less made a post on this exact issue on the old forums (can't find it anymore in any archive). Consensus was that you should use more timers instead of a single timer that does everything.
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.
Markski
Offline

Burgershot Clerk

Posts: 127
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: La Plata, Argentina
#4
2021-01-22, 08:57 PM
depends on what the code does, If it's very complex code then it should be on it's own timer. If it's dumb stuff like checking the state of variables and -- or ++'ng stuff every 1 second or whatever, then you can bundle all of that in a single func. Microoptimizations like having every single little thing on it's own timer only go so far before they have no effect and only make your code harder to look at
Website
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode