Skip to content

$component

Find components, send them events, and control which of your events are active.

22 natives. Read-only natives only look things up; the rest change something. Parameter types use the language's names (Types).

cast

read-only
$component.cast(component: Component, exact: bool, script_name: string) -> Component

Converts a component ref from one type to another if safe to do so, or generates a warning and returns NULL if the types are not compatible.

ParameterTypeMeaning
componentComponentThe component to attempt to cast.
exactboolTrue to only match the exact type (no derived types).
script_namestringThe script name.

Returns Component: The converted value, or NULL if the value was nor compatible.

get

read-only
$component.get() -> Component

Get the calling component.

Returns Component: The component.

get_entity

read-only
$component.get_entity(component: Component) -> Entity

Gets the entity holding a component.

ParameterTypeMeaning
componentComponentThe component to get the entity from.

Returns Entity: The entity

get_event_source

read-only
$component.get_event_source() -> Component

Gets the component that triggered the current event, if any.

Returns Component: A component or nullcomponent.

get_index

read-only
$component.get_index() -> int

Get the calling component's index within its entity's component list.

Returns int: The index of the specified component within its entity's component list; otherwise, -1 in the event of an error.

get_job_self_sort_order

read-only
$component.get_job_self_sort_order(component: Component) -> int

Gets the sort key for the specified component. See component.set_job_self_sort_order.

ParameterTypeMeaning
componentComponentThe component to set.

Returns int: The self sort key value.

get_parallel_id

read-only
$component.get_parallel_id() -> int

Returns the id (index) of the invocation for a parallel loop. Returns 0 when not called from a parallel loop.

Returns int: The id (index) of the invocation for a parallel loop.

get_singleton

read-only
$component.get_singleton(script_name: string, owner: User) -> Component

Retrieve a component of which there is assumed to be only one instance.

ParameterTypeMeaning
script_namestringThe script name.
ownerUser(Optional) Filters results to only values owned by the indicated user. Omit to return all results. Warns on NULL.

Returns Component: The component or null if not found.

has_event

read-only
$component.has_event(target: Component, event_name: string) -> bool

Return true if the specified target has or is a component that has an event of the given name.

ParameterTypeMeaning
targetComponentThe target entity or component to check.
event_namestringThe name of the event to look for.

Returns bool: True if the target has or is a component that has the given event, false otherwise.

has_var

read-only
$component.has_var(component: Component, var_name: string) -> bool

Return true if the given component has a var (mutable) of the given name. 'const's are *not* checked.

ParameterTypeMeaning
componentComponentThe component to check.
var_namestringThe name of the var to look for.

Returns bool: True if the component has the var, false otherwise.

is_fully_created

read-only
$component.is_fully_created(component: Component) -> bool

Gets whether the entity owning a component is created yet or not (i.e. if it's safe to call functions)

ParameterTypeMeaning
componentComponentThe component to check.

Returns bool: True if it is, false otherwise.

is_of_type

read-only
$component.is_of_type(component: Component, exact: bool, script_name: string) -> bool

Gets whether or not a component is a given type.

ParameterTypeMeaning
componentComponentThe component to check.
exactboolTrue to only match the exact type (no derived types).
script_namestringThe script name.

Returns bool: True if the component is of the specified type, false otherwise.

parallel_loop

read-only
$component.parallel_loop(func: string, target: Component, args: list, count: int, allow_non_const: bool) -> list

Returns a list that is the results of calling the supplied function on the target component as requested. Must be a const function unless allow_non_const is true.

ParameterTypeMeaning
funcstringName of the function to invoke in parallel.
targetComponentComponent to run the function on. Current component if not specified.
argslistArgs to pass to the function.
countintNumber of invocations to run in parallel.
allow_non_constboolAllow non-const functions to be called. Care must be taken to avoid race conditions or stomping.

Returns list: Results of calling func, sized to count.

print

read-only
$component.print(component: Component)

Print component information to the console.

ParameterTypeMeaning
componentComponentThe component.

queue_event

read-only
$component.queue_event(name: string, target: Component, args: list, end_of_frame: bool)

Enqueue an event on a specific component.

ParameterTypeMeaning
namestringName of the event.
targetComponentThe recipient of the event.
argslistEvent arguments.
end_of_frameboolIf true, the event is queued to run at the end of the frame, otherwise it runs at the end of the active event.

read_nondeterministic

read-only
$component.read_nondeterministic(component: Component, field: string) -> var

Read a field on a component without synchronizing. Returns nondeterministic and possibly unexpected values. Use with extreme care.

ParameterTypeMeaning
componentComponentThe component to read from
fieldstringThe name of the field to read

Returns var: The value of the field.

set_event_enabled

$component.set_event_enabled(name: string, enabled: bool, component: Component)

Enables or disables an event on a component. Generally only safe to use outside the event being enabled/disabled.

ParameterTypeMeaning
namestringThe name of the event.
enabledbooltrue to enable the event, false to disable.
componentComponentThe component to set event state. Or null to set the state of the calling component.

set_job_self_sort_order

$component.set_job_self_sort_order(component: Component, value: int)

Sets the sort key for the specified component. Used with type.setup_job_self_sort to improve performance in some cases.

ParameterTypeMeaning
componentComponentThe component to set.
valueintSort key value to use to sort among components.

take_control

$component.take_control(component: Component)

Attempts to take control of another component.

ParameterTypeMeaning
componentComponentThe component to take control of.

try_cast

read-only
$component.try_cast(component: Component, exact: bool, script_name: string) -> Component

Converts a component ref from one type to another if safe to do so, or silently NULL if the types are not compatible.

ParameterTypeMeaning
componentComponentThe component to attempt to cast.
exactboolTrue to only match the exact type (no derived types).
script_namestringThe script name.

Returns Component: The converted value, or NULL if the value was nor compatible.

try_queue_event

read-only
$component.try_queue_event(name: string, target: Component, args: list, end_of_frame: bool)

Try to enqueue an event on a specific component. Does not assume the event exists on the component.

ParameterTypeMeaning
namestringName of the event.
targetComponentThe recipient of the event.
argslistEvent arguments.
end_of_frameboolIf true, the event is queued to run at the end of the frame, otherwise it runs at the end of the active event.

Compiler helpers

The engine marks these as emitted by its own compiler. Most have shorthand in this language; prefer it where the guide shows one. Some are still the only way to do something, and the cookbook uses those deliberately.

call_function

read-onlycompiler helper
$component.call_function(alias: string, func_name: string, signature_hash: int, argc: int) -> var

function_alias(...) SYNTAX*** Calls a function on another component. Caller must have control of the function already.

ParameterTypeMeaning
aliasstringThe alias of the function to be invoked.
func_namestringThe true name of the function to invoke.
signature_hashintThe hash of the function signature to invoke.
argcintThe number of function args on the stack.

Returns var: The return value of the invoked function