karimoldacc/inline-timers
This include allows you to use inline functions as callbacks for timers, similiar to inline dialog callbacks and inline MySQL callbacks.
Install with sampctl
sampctl package install karimoldacc/inline-timers
Run this in your project folder. sampctl downloads the package and what it depends on.
Adds its include files, with the libraries it depends on, to the Pawn compiler in your browser, ready to include in a script.
Depends on 2 packages
- sampctl/samp-stdlibnot in this directory
- pawn-lang/YSI-Includes★ 227
README.md
inline_timers
This include allows you to use inline functions as callbacks for timers, similiar to inline dialog callbacks and inline MySQL callbacks.
There is no support for passing extra arguments through this, because the variables (and arguments) in the parent function are accessible in the inline function as well due to a feature called "closuers", thus rendering the usage of the extra arguments useless. This is however a feature of YSI itself and it has nothing to do with this include.
Installation
Simply install to your project:
sampctl package install ltkarim/inline-timers
Include in your code and begin using the library:
#include <inline_timers>
Usage
SetInlineTimer(callback: callback, delay, repeat)
- Parameters:
callback: The inline callback to use.delay: The interval of the timer in milliseconds.repeat: whether the timer should repeat or not.- Returns:
falseon failure,IDto be used withKillInlineTimeron success.
Starts a timer with the specified interval.
NOTE: This function does NOT return the timer ID, rather the malloc address that contains the timer ID and callback data. You can't use KillTimer to kill it!
KillInlineTimer(timer)
- Parameters:
timer: The timer ID returned bySetInlineTimer.- Returns:
trueregardless of the result.
Stops the specified timer.
NOTE: Inline timers have to be killed with the above function since it allocates extra memory that need to be freed.
Example:
new
someInt = 1337,
someStr[] = "hello world",
Float: someFloat = 1.337
;
inline TimerTest()
{
printf(" TimerTest called after 3 seconds! %i, %s, %0.3f", someInt, someStr, someFloat);
}
SetInlineTimer(using inline TimerTest, 3000, false);
Outputs:
TimerTest called! 1337, hello world, 1.337
Dependencies
- YSI
- y_malloc
- y_inline
Testing
To test, simply run the package:
sampctl package run
Credits
This page is built from what GitHub publishes about the repository. samp.directory does not host the code. Report a problem with this listing