• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] YSI Logic user-incomprehension and usage
#4
Okay, so timers come in two forms, one being a regular timer and another being a repeater. A regular timer has a keyword associated with it called `defer` which means to delay a call to a function, now you can defer a function for n times, n being the number of milliseconds you wish to delay.

An example of this would go as follows:
Code:
main() { ? ? // uses the 'defer' keyword to associated it with YSI, ? ? // and a function name and it's parameters is required afterwards? ? ? defer CheckPlayer(12); ? ? // You can override the delay set on the timer function, which is enclosed ? ? // in square brackets `[500]` by also putting square brackets with a new timer ? ? // delay inbetween? ? ? defer CheckPlayer[1000](12); // this will override the delay in the function and instead wait 1 second ? ?? } // The 'timer' is a keyword that YSI uses to associated this function with YSI // The number enclosed within square brackets `[500]` is the number of seconds the timer // will be delayed for timer CheckPlayer[500](playerid) { ? ? // Perform some checks, or what you would normally do if this was a standard timer (SetTimer(Ex)) ? ? if(IsPlayerConnected(playerid)) { ? ? ? ? printf("The player is connected"); ? ? } }

We than have repeatable timers. These timers run until manually stopped, and they can be stopped by using the `stop` keyword. To create a repeatable timer, you instead use the `repeat` keyword instead of the `defer` keyword. Here is an example:

Code:
static Timer: repeatable_timer; main() { ? ? // Here we are storing the timer globally, so it can later be stopped else ? ? // where in the script. Though this is only needed if the timer is to ever be stopped ? ? // timers are generally managed internally to YSI, so will be stopped when the server exits ? ? // or when the gamemode ends. ? ? repeatable_timer = repeat CheckPlayer(12); ? ? // We can also override the default delay for the function ? ? repeatable_timer = repeat CheckPlayer[1000](12); // The delay value is overridden to run every 1 second } // The 'timer' is a keyword that YSI uses to associated this function with YSI // The number enclosed within square brackets `[500]` is the number of seconds the timer // will be delayed for timer CheckPlayer[500](playerid) { // Perform some checks, or what you would normally do if this was a standard timer (SetTimer(Ex)) if(IsPlayerConnected(playerid)) { printf("The player is connected"); } // Lets now stop the repeatable timer just as an example stop repeatable_timer; }

I hope this is enough to make you understand when to use them and how to use them. Feel free to ask anymore questions :)
Remember to always refer to J0sh as `J0sh...`

# Services/Platforms

forum.open.mp (Forum Manager)

open.mp (Member)

Pawn Playground (Creator/Maintainer)

Pawn Packages (Creator/Maintainer)
  Reply


Messages In This Thread
RE: YSI Logic user-incomprehension and usage - by JustMichael - 2019-12-18, 07:39 PM