Running Things a Few Frames Later - Skirlez/nubbys-forgery GitHub Wiki

Title

mod_run_delayed(frames, function)

Runs function in frames frames.

Example:

in GML

mod_run_delayed(30, function () {
    mod_log("Hello!")
})

in Catspeak

mod_run_delayed(30, fun {
    mod_log("Hello!")
})

This code will print "Hello!" in 30 frames.

It should be noted the internal timer(s) used to queue these functions tick down in the Begin Step event. Meaning if you call this function in Step, End Step, or any event that happens after Begin Step, it will start ticking down on the next frame (which is probably what you want). But, if you call this function in Begin Step, you cannot predict if the timer will start ticking down on that frame or on the next. So don't do that if you care about precise timing.

It is valid to pass 0 into frames, which will execute your function as soon as the modloader iterates on the queue.

It is invalid to pass "g", which will Explode the game.

The modloader will automatically clean up any of your functions that are in the queue when your mod is unloaded, so don't worry about that.