This category contains API elements related to the entity system.
Related sample code
add_instance_to_tags ( self, instance, tags )Tags an instance with a number of tags that can later be used to efficiently query instances by tags.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
instance : | integer | The component instance. |
tags : | string* | A variable number of strings representing the tags to add to the component instance. The * notation indicates that there may be zero or more instances of the specified type. |
This function does not return any values. |
Other related reference items
entities_with_script ( self, script_name ) : stingray.Entity[]Returns all entities linked to the specified script name.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
script_name : | string | Name of the script. |
An array of entities linked to the script name. The [] notation indicates that this type is an array: a table in which the keys of the members are sequential integers, and the value of each element is an instance of the type shown. |
Other related reference items
instance_ids_with_script ( self, entity, script_name, result_table ) : any(stingray.Entity, integer)[], integerinstance_ids_with_script ( self, script_name, result_table ) : any(stingray.Entity, integer)[], integerReturns all script component instances linked to the specified script name.
|
self : | Specifies the object instance that this function will act on. You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation. | |
entity : | An optional entity to query for script components. | |
script_name : | string | Name of the script. |
result_table : | table? | An optional table for the result. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any(stingray.Entity, integer)[] |
Interleaved pairs of entities and component instance ids. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. The [] notation indicates that this type is an array: a table in which the keys of the members are sequential integers, and the value of each element is an instance of the type shown. |
integer |
The number of results written to the table. |
Example usage:
-- We can pass a cached table for better performance or we can omit the parameter and have it allocated for us.
local components, num_components = script_component:instances_with_script("myscript_name", self._query_cache)
local arg1 = -- some argument
local arg2 = -- some argument
script_component:call_function(components, "some_function", arg1, arg2)
local entity = -- some entity
local arg1 = -- some argument
local arg2 = -- some argument
local components = script_component:instances_with_script(entity, "myscript_name", self._query_cache)
script_component:call_function(components, "some_function", arg1, arg2)
Other related reference items