Wiki

Clone wiki

NuclearThroneTogether / Scripting / API / Script binding

Mod development sometimes requires you to have code that executes at some particular time or depth.

While most mod types offer at least two callbacks (step and draw), these are often not sufficient to accomplish the goals.

For this reason, Nuclear Throne Together features a number of functions that allow to make a script execute in a particular event and at a particular depth:

script_bind_begin_step(script, depth:number, ...args)
script_bind_step(script, depth:number, ...args)
script_bind_end_step(script, depth:number, ...args)
script_bind_draw(script, depth:number, ...args)
The way this works is as following: * The function takes a script id/name, depth, and any number of custom arguments. * The function creates a special instance (CustomStep/CustomDraw/etc.) at the given depth, stores a reference to the script, and the arguments. This instance is also returned from the function. * Every frame (in according event) the special instance calls your script with given arguments, meaning that you can store variables in it and destroy it when it's time.

example.mod.gml:

#define step
with (Player) if (button_pressed(index, "horn")) {
    with (script_bind_draw(scr_test, -10, mouse_x[index], mouse_y[index], "Hello!")) {
        time = 0;
    }
}

#define scr_test(dx, dy, text)
draw_text_nt(dx, dy, text);
time += 1;
if (time >= 90) instance_destroy();

script_ref_create

A somewhat close relative of script_bind_ functions, script_ref_create is used for creating script references for custom object' event callback variables. The syntax is as following:

script_ref_create(script, ...args)
Note that for events that already accept arguments, custom arguments specified will be passed after the "built-in" ones.

Updated