The Functional Object - Skirlez/nubbys-forgery GitHub Wiki
The modloader provides obj_functional_object
in case you need to program your own object.
You create the object using either instance_create_depth
or instance_create_layer
. In the optional var_struct
parameter, you can pass in functions that correspond to object events.
Here is a list of functions you can pass in:
on_create
on_destroy
on_clean_up
on_begin_step
on_step
on_end_step
on_draw
on_draw_gui_begin
on_draw_gui
on_draw_gui_end
on_pre_draw
on_post_draw
on_room_start
on_room_end
on_async_image_loaded
on_async_http
Usage notes
- In the functions you pass in,
self
will refer to the functional object instance. You can use it to access the instance's variables. - If you're not drawing anything, consider setting the object's
visible
variable to false. It will save a few useless checks. - Make sure to pass in a
name
variable invar_struct
as well. This name will be logged in case the object errors. - You are allowed to initialize or change these functions post-creation, but be wary! doing this, for example:
let inst = instance_create_depth(0, 0, 0, obj_functional_object)
inst.on_create = fun {
-- code
}
inst.name = "my cool object"
Will cause on_create
to not get executed, because the Create event already happens by the time you set it.
It will also cause the name to get ignored, as the modloader expects that variable to be initialized when Create is ran.
Example use
let inst = instance_create_depth(0, 0, 0, obj_functional_object, {
name : "my cool object",
on_create : fun {
-- code can go here
-- making sure to use `self` for instance variables
self.a = 0
},
on_step : fun {
-- code can go here
self.a += 1
},
-- not using any draw events
visible : false,
})
Example mod's supervisors/supervisor.meow
: https://github.com/Skirlez/nubbys-forgery-example-mod/blob/main/supervisors/example_supervisor.meow