Macros & APIs
Back to ScriptsCommon macros and runtime helpers used by scripts. Most macros take short closures so runtime borrows end at closure exit instead of leaking across large blocks.
Signature Index
// node / scenecreate_node!(ctx, NodeType, name?, tags?, parent?) -> NodeIDwith_node!(ctx, NodeType, node_id, |node| -> V { ... }) -> Vwith_node_mut!(ctx, NodeType, node_id, |node| -> V { ... }) -> Option<V>with_base_node!(ctx, BaseType, node_id, |node| -> V { ... }) -> Vwith_base_node_mut!(ctx, BaseType, node_id, |node| -> V { ... }) -> Option<V>reparent!(ctx, node_id, new_parent_id) -> ()remove_node!(ctx, node_id) -> () // state / scriptwith_state!(ctx, StateType, node_id, |state| -> V { ... }) -> Vwith_state_mut!(ctx, StateType, node_id, |state| -> V { ... }) -> Option<V>get_var!(ctx, node_id, member) -> Variantset_var!(ctx, node_id, member, value) -> ()call_method!(ctx, node_id, method, params) -> VariantNode / Scene
create_node!(ctx, Type, name?, tags?, parent?)with_node!returns data;with_node_mut!mutates datawith_node_mut!returnsOption<V>, so mutation closures can return computed values- closure return types keep read/mutate operations explicit
reparent!/remove_node!
State & Scripts
with_state!/with_state_mut!with_state_mut!returnsOption<V>from closure return valueget_var!/set_var!call_method!/method!("name")- use
params![...]+variant!(...)for dynamic boundary values
Macro Pages by Subsystem
Node access macros: with_node*, with_base_node*, create_node!State macros: with_state*, get_var!, set_var!Query macros: query!, query_first!, gates/predicatesSignal macros: signal_connect!, signal_emit!, signal_disconnect!ID/value helpers: var!, method!, signal!, params!, variant!Input macros by device: keys, mouse, gamepads, joy-cons, players
Example
// create nodelet id = create_node!(ctx, Node2D, "MyNode", ["tag"], parent_id); // state accesswith_state_mut!(ctx, PlayerState, id, |s| s.health -= 1); // node read returns datalet texture = with_node!(ctx, Sprite2D, id, |node| node.texture);let transform = with_node!(ctx, Sprite2D, id, |node| (node.position, node.visible)); // node mutatewith_node_mut!(ctx, Sprite2D, id, |node| node.texture = texture); // call method dynamicallycall_method!(ctx, id, method!("tick"), params![42]);