[Include] inline-timers: Use y_inline functions with timers!
#1

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",
    
FloatsomeFloat 1.337
;
inline TimerTest()
{
    
printf(" TimerTest called after 3 seconds! %i %s %0.3f"someIntsomeStrsomeFloat);
}
SetInlineTimer(using inline TimerTest3000false); 
Outputs:

Code:
TimerTest called! 1337, hello world, 1.337
Dependencies

  • YSI
    • y_malloc
    • y_inline
Testing


To test, simply run the package:

Code:
sampctl package run
Credits

Reply
#2

Good job.
Reply
#3

Quote:
Originally Posted by [HLF]Southclaw
View Post
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!
Reply
#4

Maybe you could extend this to textdraws/playertextdraws as well?
Reply
#5

What's different with y_timers or default SetTimer function? and can you explain what is inline? Thank you.
Reply
#6

Quote:
Originally Posted by Pottus
View Post
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_
View Post
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 TimerTest3000false);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)