Docs

Script Methods

Docs Index

Purpose

methods! defines reusable behavior on a script. Local methods can be called directly, and dynamic or cross-script calls use call_method!.

Script Methods explains behavior, constraints, and practical usage so implementation decisions stay consistent across scripts and scenes.

API Source

Functions

methods!call_method!with_state!with_state_mut!

Enums

// not documented yet for this module

Constants

first arg after &self is ScriptContext

Types

ScriptContextVariantScriptMemberID

Usage Pattern

methods!({    fn take_damage(&self, ctx, amount: i32) {        with_state_mut!(ctx.run, EnemyState, ctx.id, |state| {            state.health -= amount;        });    }});

API Breakdown

methods! reusable handlers

methods!({    fn method_name(        &self,        ctx: &mut ScriptContext<'_, RT, RS, IP>,        /* custom args */    ) -> ReturnType { ... }});

Params

first arg after &self is ctx: &mut ScriptContext

custom args must cross Variant boundary when used by call_method!

ReturnType should be Variant-safe for dynamic dispatch

Returns

direct Rust call returns typed ReturnType; call_method! returns Variant

Fail Modes

call_method! returns Variant::Null-like default when method id missing or target has no matching script member

invalid param conversion at dynamic boundary yields default/fallback behavior on receiving side

Example

methods!({    fn take_damage(&self, ctx: &mut ScriptContext<'_, RT, RS, IP>, amount: i32) {        let _ = with_state_mut!(ctx.run, EnemyState, ctx.id, |state| {            state.health -= amount;        });    }});

Use methods! for script-local reusable behavior and as explicit call_method! targets from other nodes/systems.

Key Details

Methods use the same leading args as lifecycle hooks.

Custom typed params and returns must be Variant-safe.

Use direct Rust calls inside the same script when possible.

Use call_method! for dynamic dispatch by method id/name.