Last active
April 28, 2024 21:22
-
-
Save williammustaffa/1d78501b080c69e421d2c8fe704c21f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function seconds_to_gamespeed(_seconds) { | |
return game_get_speed(gamespeed_fps) * _seconds; | |
} | |
/** | |
* new Timer(_bind, _callback) | |
* @param _bind scope of the callback, usually the | |
* @param _callback function to be executed | |
* | |
* Methods | |
* stop: cancel timer | |
* step: MUST be added to step event | |
* trigger: trigger callback instantly | |
* set: receive _seconds as argument, and trigger callback after x seconds | |
*/ | |
function Timer(_bind, _callback) constructor { | |
callback = _callback; | |
bind = _bind; | |
time = -1; | |
active = false; | |
static step = function () { | |
if (active) { | |
time--; | |
if (time <= 0) { | |
stop(); | |
trigger(); | |
} | |
} | |
} | |
static stop = function () { | |
time = -1; | |
active = false; | |
} | |
static set = function (_seconds) { | |
time = seconds_to_gamespeed(_seconds); | |
active = true; | |
} | |
static trigger = function () { | |
if (is_method(callback)) { | |
method(bind, callback)(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment