inline-timers: Use y_inline functions with timers! -
iKarim - 27.03.2018
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:
Code:
sampctl package install ltkarim/inline-timers
GitHub:
https://github.com/ltkarim/inline-timers
Include in your code and begin using the library:
PHP Code:
#include <inline-timers>
Usage
Example:
PHP Code:
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:
Code:
TimerTest called! 1337, hello world, 1.337
Dependencies
Testing
To test, simply run the package:
Code:
sampctl package run
Credits
Re: inline-timers: Use y_inline functions with timers! -
NelsonC - 27.03.2018
Good job.
Re: inline-timers: Use y_inline functions with timers! -
iKarim - 20.04.2018
Quote:
Originally Posted by [HLF]Southclaw
Damn I missed this, I'm surprised this isn't part of YSI already tbh. *stares at ******* Nice work!
|
I always thought it's a feature of y_timers too!
Re: inline-timers: Use y_inline functions with timers! -
Pottus - 21.04.2018
Maybe you could extend this to textdraws/playertextdraws as well?
Re: inline-timers: Use y_inline functions with timers! -
Fairuz - 21.04.2018
What's different with y_timers or default SetTimer function? and can you explain what is inline? Thank you.
Re: inline-timers: Use y_inline functions with timers! -
iKarim - 21.04.2018
Quote:
Originally Posted by Pottus
Maybe you could extend this to textdraws/playertextdraws as well?
|
Inline textdraw click callbacks? It's possible, but I'd say it doesn't belong to this include, since this is dedicated to timers. I'll take a look though.
Quote:
Originally Posted by Dice_
What's different with y_timers or default SetTimer function? and can you explain what is inline? Thank you.
|
y_timers is a part of the YSI libraries, it basically extends/simplifies what you can do with normal timers, you can read more about it here:
https://sampforum.blast.hk/showthread.php?tid=571044
Inline functions are also a part of the YSI libraries, y_inline, it's sort of similar to anonymous functions in JavaScript or any other language, it can be used with y_dialog, BlueG's MySQL plugin and timers with this include.
PHP Code:
main()
{
inline TimerTest()
{
printf("called");
}
SetInlineTimer(using inline TimerTest, 3000, false);
}