Represents a game world.
Constructors and accessors
stingray.Application.flow_callback_context_world() stingray.Application.main_world() stingray.Application.new_world() stingray.Application.worlds() stingray.Level.world() stingray.Unit.level() |
Related sample code
Other related reference items
Related help topics
delta_time ( self ) : numberRetrieves the delta time value used during the last world update.
|
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. |
number |
The delta time value. |
entities ( self ) : stingray.Entity[]Returns a table with all the entities in the world.
|
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. |
A table with all the entities in the world. 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. |
replay ( self ) : stingray.Replay?Returns a Replay object, which you can use to replay events in the world.
|
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. |
The replay object owned by the world, or nil if the replay system was not enabled for the world. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
Other related reference items
scatter_system ( self ) : stingray.ScatterSystemReturns the scatter brush system owned by the world.
|
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. |
The scatter system owned by the world. |
The brush system is used for mass unit spawning.
Related sample code
storyteller ( self ) : stingray.StoryTellerReturns the StoryTeller for the world, which you can use to play stories or cutscenes.
|
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. |
The storyteller owned by the world. |
Other related reference items
time ( self ) : numberRetrieves the current time in the world: i.e. the sum of all the delta times for every update since the world was created.
|
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. |
number |
The current time in the world. |
Related sample code
update ( self, delta_time )Updates the engine representation of the world.
|
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. | |
delta_time : | number? | The time step that the world should use when updating. Optional; if not specified, the application's global time step will be used. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
You should typically call this function in your implementation of the update() callback you provide to the engine in your Lua boot script.
Instead of calling update(), you can call update_animations() and then update_scene() separately. This allows your boot script to do some processing in between the update of the animations and the update of the scene.
update_animations ( self, delta_time )Updates the animations in the world.
|
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. | |
delta_time : | number? | The time step that the world should use when updating. Optional; if not specified, the application's global time step will be used. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
Other related reference items
update_animations_with_callback ( self, delta_time, callback )As update_animations(), but calls the callback function you provide during the animation player update.
|
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. | |
delta_time : | number | The time step that the world should use when updating. |
callback : | fun(nil:nil) | A callback function that will be invoked. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
This function does not return any values. |
This may be useful on the PlayStation 3, because the animation player update runs entirely on the SPUs, which frees the PPU to do other things. Thus, you can save precious milliseconds by putting some of your Lua updates in the callback function so that its code can be executed in parallel. Note that you must not create or destroy animations in the callback, since that would interfere with the update of the animation player.
update_scene ( self, delta_time )Updates the physics and scene graphs in the world.
|
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. | |
delta_time : | number? | The time step that the world should use when updating. Optional; if not specified, the application's global time step will be used. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
Other related reference items
get_data ( self, indices ) : anyRetrieves the data set at the specified indices within the world's script data object from the world.
|
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. | |
indices : | any(integer, string)+ | One or more indices for the data, which may be integers or strings. The + notation indicates that there may be one or more instances of the specified type. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
any |
The data previously saved at the specified sequence of indices. |
Similar to Unit.get_data().
Other related reference items
has_data ( self, indices ) : booleanIndicates whether or not any data has been saved at the specified indices in the world's script data object.
|
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. | |
indices : | any(integer, string)+ | One or more indices for the data, which may be integers or strings. The + notation indicates that there may be one or more instances of the specified type. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
boolean |
Returns true if a data value is stored at the specified sequence of indices, or false otherwise. |
Similar to Unit.has_data().
set_data ( self, indices, indices, indices, value ) set_data ( self, indices, indices, value ) set_data ( self, indices, value )Stores the specified value in the world's script data object, at a location determined by the specified indices.
|
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. | |
indices : | any(integer, string) | One or more indices for the data, which may be integers or strings. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
value : | any | The value to store. |
This function does not return any values. |
You can retrieve the data later by passing the same indices in a call to get_data(). Similar to Unit.set_data().
clear_permanent_lines ( self )Clears any permanent debug lines that have been drawn into the world.
|
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. |
This function does not return any values. |
create_line_object ( self, disable_depth_test ) : stingray.LineObjectCreates a new line object to be used for debug drawing.
|
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. | |
disable_depth_test : | boolean? | If true, lines will be drawn without depth test. Optional; default is false. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly created line object. |
Other related reference items
debug_camera_pose ( self ) : stingray.Matrix4x4Returns the position and orientation of the last camera that was used to render the world.
|
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. |
The position and orientation of the camera. |
Other related reference items
destroy_line_object ( self, line )Destroys a line object previously created by a call to create_line_object().
|
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. | |
line : | The line object to be destroyed. |
This function does not return any values. |
The elements in this group are only available in development builds.
Do not use them in your final builds.
num_particles ( self, effect_id, cloud_index ) : integerReturns the number of active particles in a world, a particle effect, or a cloud.
|
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. | |
effect_id : | integer? | The ID of the particle effect. Optional; if specified, the return value will give the number of particles in the specified particle effect only. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
cloud_index : | integer? | The index of a particle cloud. Optional; if specified, the return value will give the number of particles in the specified cloud only. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
integer |
The number of active particles. |
set_frustum_inspector_camera ( self, camera )Passing in a camera to this function overrides the regular camera passed to Application.render_world(), after all culling has been performed.
|
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. | |
camera : | The override camera. |
This function does not return any values. |
This may be very useful for debugging problems related to culling.
create_screen_gui ( self, x, y, params ) : stingray.GuiCreates a new screen space Gui at pixel coordinates (x,y).
|
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. | |
x : | number? | The x coordinate of the screen space. Optional. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
y : | number? | The y coordinate of the screen space. Required if and only if x is specified. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
params : | any(string, number)* | Settings for the gui. The possible values are:
The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. The * notation indicates that there may be zero or more instances of the specified type. |
The newly created gui. |
(0,0) is the bottom left corner of the screen.
Note that to find the size of the screen, you can call Application.back_buffer_size().
Related sample code
Other related reference items
create_video_player ( self, resource, loop ) : stingray.VideoPlayerCreates a new VideoPlayer that plays the specified .IVF resource.
|
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. | |
resource : | string | The video resource to play. |
loop : | boolean? | Determines whether or not the video loops. If true, the video will continue playing to the start when it reaches the end, otherwise it will freeze at the last frame. Optional; the default is true. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly created video player. |
The video player can be used with Gui video objects.
This function will return trigger a script error if the video player is not supported. To test if the video player is supported, use [has_video_player()].
Note: This video playing interface is under development. It should be considered temporary and currently only works on Windows platforms.
Other related reference items
create_world_gui ( self, pose, width, height, params ) : stingray.GuiCreates a new Gui that lives in the 3D world.
|
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. | |
pose : | The position and orientation of the gui in 3D space. | |
width : | number | The ratio between Gui units and world space units along the X axis of the Gui's drawing plane. Increasing this value causes shapes drawn in the Gui to appear smaller than in world space, and vice-versa. |
height : | number | The ratio between Gui units and world space units along the Y axis of the Gui's drawing plane. Increasing this value causes shapes drawn in the Gui to appear smaller than in world space, and vice-versa. |
params : | string* | Settings for the gui. The possible values are:
The * notation indicates that there may be zero or more instances of the specified type. |
The newly created gui. |
Other related reference items
destroy_gui ( self, gui )Destroys a gui created with create_screen_gui() or create_world_gui().
|
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. | |
gui : | The gui to remove from the world. |
This function does not return any values. |
destroy_video_player ( self, video_player )Destroys the video player created by create_video_player().
|
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. | |
video_player : | The video player to remove. |
This function does not return any values. |
Video players consume a lot of resources, so you should destroy the video player as soon as you are done with it.
get_gui_by_id ( self, id ) : stingray.GuiReturns the Gui with that ID in the world.
|
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. | |
id : | integer | The id of the gui |
The gui with that id. |
destroy_level ( self, level )Destroys the specified level and all units spawned by the level (or units placed in the level editor) when loaded.
|
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. | |
level : | The name of the level you want to destroy. |
This function does not return any values. |
Take care to clean up the units spawned in Lua (or in the level flow editor) for these are not destroyed when the level is unloaded. You are not required to call this function, since all levels will be destroyed when the world ends. Nested levels cannot be destroyed using this function.
levels ( self ) : stingray.Level[]Returns all the levels in the world.
|
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. |
A table that contains all levels in the world. 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. |
Note that the table returned by this function does not contain nested levels; use Level.nested_levels() to access those.
load_level ( self, name, position, rotation, scale ) : stingray.LevelLoads the named level into the world at the specified position, rotation, and per-axis scale factors.
|
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. | |
name : | string | The name of the level you want to load. |
position : | Optional; the position of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
rotation : | Optional; the rotation of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
scale : | Optional; the per-axis scale factors of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The loaded level in the world. |
If position, rotation, scale are not supplied, the level will be loaded at the world origin with the default rotation and scale.
Other related reference items
load_level_with_object_sets ( self, name, obj_set_names, ignored_obj_set_names, position, rotation, scale ) : stingray.LevelIdentical to load_level(), but does not spawn any objects that are members of object sets unless explicitly told to do so.
|
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. | |
name : | string | The name of the level you want to load. |
obj_set_names : | string[] | A table that contains the names of the object sets to spawn. 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. |
ignored_obj_set_names : | string[] | A table that contains object set names that will be ignored. 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. |
position : | Optional; the position of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
rotation : | Optional; the rotation of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
scale : | Optional; the per-axis scale factors of the level. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The loaded level in the world. |
Units, particle effects, sounds, triggers, prototypes and volumes can be added to object sets using the level editor. An object can belong to several object sets. An object will be spawned if any of these conditions is true:
For performance reasons, prototypes and volumes do not take the ignored_object_set_names parameter into account. They are spawned only if they are members of any of the named object sets, or if they do not belong to any object set. This allows the engine to merge prototype and volume geometry into larger batches.
You can get a list of all object set names within a level resource by calling the LevelResource.object_set_names() function.
num_level ( self ) : integerReturns the number of levels in the world.
|
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. |
integer |
The total number of levels in the world. |
are_particles_playing ( self, effect_id ) : booleanIndicates whether or not the particle effect with the specified ID is currently spawning particles.
|
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. | |
effect_id : | integer | The integer ID of the particle effect to test. |
boolean |
true if the particle effect is spawning particles, or false otherwise. |
create_particles ( self, effect_name, position, rotation, scale ) : integerCreates a new particle effect with the specified name at the specified position, with the specified rotation and per-axis scale factor.
|
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. | |
effect_name : | string | The name of the particle effect to be created. |
position : | The position of the particle effect. | |
rotation : | The orientation of the particle effect. Optional. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
scale : | The scaling factor of the particle effect. Optional. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
integer |
An integer ID for the newly created particle effect. |
destroy_particles ( self, effect_id )Destroys the particle effect with the specified id.
|
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. | |
effect_id : | integer | The integer ID of the particle effect to be destroyed. |
This function does not return any values. |
find_particles_variable ( self, effect_name, variable_name ) : integerFinds the index of a particle effect variable with the specified 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. | |
effect_name : | string | The name of the particle effect whose index will be checked. |
variable_name : | string | The name of the variable to find within the particle effect. |
integer |
The index of the specified variable within the particle effect. |
link_particles ( self, effect_id, unit, object, pose, orphaned_policy )Links the particle effect with the specified ID to the specified unit.
|
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. | |
effect_id : | integer | The integer ID of the particle effect to link. |
unit : | The unit to which the particle effect will be linked. | |
object : | integer | The index of the target node in the unit's scene graph. |
pose : | The new local coordinates of the particle system relative to object. | |
orphaned_policy : | string | Determines what happens to the particle effect if the unit is destroyed. May be any of the following values:
|
This function does not return any values. |
The effect is linked to the specified object within the unit's scene graph. Its new coordinates are determined by the pose argument, which should be expressed in the local coordinate system of the parent object.
move_particles ( self, effect_id, position, rotation, scale )Moves the spawn point of the particle effect with the specified id to the given position and rotation, with the specified per-axis scale factor.
|
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. | |
effect_id : | integer | The integer ID of the particle effect to move. |
position : | The new position of the particle effect. | |
rotation : | The new orientation of the particle effect. Optional. The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
scale : | The new scaling factor of the particle effect. Optional. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
Note that existing particles are not affected.
set_particles_collision_filter ( self, collision_filter )Sets the collision filter to use for particle collisions.
|
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. | |
collision_filter : | string | The collision filter to set. |
This function does not return any values. |
If an effect_id is specified, the collision filter is set for just that effect. Otherwise, the default collision_filter to be used for all particle effects is set.
set_particles_variable ( self, effect_id, variable_index, value )Sets the value of the specified variable within a particle effect.
|
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. | |
effect_id : | integer | The ID of the particle effect. |
variable_index : | integer | The index of the variable whose value will be set. |
value : | The value to set for the specified variable within the particle effect. |
This function does not return any values. |
stop_spawning_particles ( self, effect_id )Stops the particle effect with the specified id from spawning.
|
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. | |
effect_id : | integer | The integer ID of the particle effect to stop. |
This function does not return any values. |
The effect will be destroyed when all the particles have been played out.
physics_world ( self ) : stingray.PhysicsWorldRetrieves the physics world maintained by the specified game world.
|
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. |
The physics world. |
Related sample code
vector_field ( self, name ) : stingray.VectorFieldRetrieves the vector field with the specified name in the world.
|
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. | |
name : | string | The name of the vector field to retrieve, such as "wind". |
The retrieved vector field. |
Other related reference items
create_shading_environment ( self, name ) : stingray.ShadingEnvironmentCreates a new ShadingEnvironment object with the specified 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. | |
name : | string | The name of the shading environment to be created. |
The newly created shading environment. |
Other related reference items
destroy_shading_environment ( self, environment )Destroys a shading environment previously created by a call to create_shading_environment().
|
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. | |
environment : | The shading environment to be destroyed. |
This function does not return any values. |
set_shading_environment ( self, environment, name )Changes the ShadingEnvironment instance to point to shading environment data with the specified 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. | |
environment : | The shading environment to be changed. | |
name : | string | The name of the new shading environment data the environment should use. |
This function does not return any values. |
destroy_unit ( self, unit )Destroys a game unit that was previously created by a call to spawn_unit().
|
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. | |
unit : | The unit to be destroyed. |
This function does not return any values. |
link_unit ( self, child, child_node_index, parent, parent_node_index ) link_unit ( self, child, parent, parent_node_index )Links a node in one unit to a node in another unit, creating a child-parent relationship.
|
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. | |
child : | The unit that will become the child. | |
child_node_index : | integer | The index of the node in the child that will be linked to the parent. Optional; if omitted, the root node of the child will be used. |
parent : | The unit that will become the parent. | |
parent_node_index : | integer? | The index of the node in the parent that will be linked to the child. Optional; if omitted, the root node of the parent will be used. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
After this call, the child object will be a slave of the parent object. Any changes you make to the parent unit's position and rotation will also be applied to the child.
Calling this function automatically resets the local transform of the child node, so that it is positioned at the exact location of the parent node, with the same rotation, and the same scale. If you want to offset the child, you need to set its local position, rotation and scale after the call to link_unit().
You can call this function multiple times in order to link different nodes in the child unit to different nodes in the parent unit. This can be used, for instance, to link up a piece of clothing to multiple skin bones in the character that is wearing the clothing.
You cannot link one child unit to nodes in different parent units. A unit must have a single, well-defined parent unit. If a unit is already linked to a parent, you must first unlink it by calling unlink_unit() before linking it to a different parent unit.
Other related reference items
num_units ( self ) : integerIndicates the number of units that have been created in the specified world.
|
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. |
integer |
The number of units in the world. |
This includes units that were placed into levels in the editor and spawned when the levels were loaded, and units that have been spawned dynamically on the fly.
spawn_unit ( self, unit_name, transform ) : stingray.UnitSpawns a new instance of a game unit at a specified location.
|
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. | |
unit_name : | string | The name of the unit to spawn. |
transform : | Optional. The starting position and orientation for the new unit. If omitted, the unit will be spawned at the default position (the origin of the 3D coordinate system), with a default rotation. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly created Unit object. |
spawn_unit ( self, unit_name, position, orientation ) : stingray.UnitSpawns a new instance of a game unit at a specified location.
|
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. | |
unit_name : | string | The name of the unit to spawn. |
position : | Optional. The starting position for the new unit. If omitted, the unit will be spawned at the default position (the origin of the 3D coordinate system). The ? notation indicates that this type is optional: there may be zero or one instances of it. | |
orientation : | The starting orientation for the new unit. If omitted, the unit will be spawned with a default rotation. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly created Unit object. |
Related sample code
Other related reference items
units ( self ) : stingray.Unit[]Retrieves all units in the specified world.
|
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. |
A table that contains all Unit objects that exist in the world. 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. |
This includes units that were placed into levels in the editor and spawned when the levels were loaded, and units that have been spawned dynamically on the fly.
units_by_resource ( self, resource_name ) : stingray.Unit[]Retrieves all unit instances of the specified resource in the world.
|
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. | |
resource_name : | string | The resource name of the units to look for. |
A table that contains all Unit objects that exist in the world and that match the specified resource type. 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. |
Related sample code
unit_by_id ( self, id ) : stingray.Unit?Finds the unit with the id id (as defined by the Level Editor) and returns it.
|
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. | |
id : | string | The id of the unit to look for. |
A unit with the specified id, or nil if no unit exists with that id. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
If no such unit exists, nil is returned.
unit_by_name ( self, name ) : stingray.Unit?Finds the unit with the name name (as set in the Level Editor) and returns it.
|
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. | |
name : | string | The name of the unit to look for. |
A unit with the specified name, or nil if no unit exists with that name. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
If no such unit exists, nil is returned. If there are multiple units with the same name, a random one will be returned.
unlink_unit ( self, child )Unlinks the specified unit from its parent, if any.
|
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. | |
child : | The unit that will be unlinked from its parent. |
This function does not return any values. |
All the linked nodes in the child are unlinked, and their local positions are reset to match their current world positions. Therefore, unlinked objects will remain where they currently are, unless you move them after they are unlinked.
Note that if you linked an object other than the root node, unlinking the unit will not relink that object back to its previous parent in the unit's scene graph. You must explicitly call Unit.scene_graph_link() to do that.
Other related reference items
update_unit ( self, unit )Forces an update of a unit's scene graph after the main world update has been performed.
|
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. | |
unit : | The unit to be updated. |
This function does not return any values. |
This can be used to implement units that are dependent on other units positions in complicated ways that cannot be expressed solely by linking units through calls to link_unit().
It is recommended that you use this approach sparingly.
Note that update_unit() does not automatically update linked child units. You have to call update_unit() on each child unit manually, if you want their positions to be updated to reflect the new position of the parent.
Related sample code