Skip to main content

World

Contains functions for finding and creating entities.

Functions

findEntity(tag)

Returns the Entity that matches the specified tag. If there are multiple entities with the same tag, only one will be returned.

Parameters

  • tag A string containing the entity tag.

Returns

The Entity that matches the tag, or nil if none was found.

Example

Get an entity with the tag "Citizen" and move it to the position (1,0,-17).

function onStart()
local entityCitizen = World.findEntity("Citizen")
if entityCitizen then
-- assert if the entity exist at that location
entityCitizen.position = Vector3.new(1,0,-17)
end
end
Result

spawn(entityCode, position, bearing, callback)

Spawns a new Entity.

Parameters

  • entityCode A string containing the Entity Code (you can find this in the inventory).
  • position A Vector3 containing the position of the Entity when it is spawned.
  • bearing A Bearing that determines which direction the Entity faces when it is spawned.

Returns

The Entity that was spawned.

Example

Spawn a Bearracuda at (-10,0,-4) facing north.

function onStart()
World.spawn("02:0004:00", Vector3.new(-10,0,-4), Bearing.North)
end
Result

getPersistentData(key)

Returns persistent data stored.

Parameters

  • key A string containing the key used to identify the data cache.

Example

Change the behaviour of an entity based on how many levels are unlocked at the start of the world.

function onStart()
--... previously set
local levelsUnlcoked = World.getPersistentData("levelsUnlcked")
if levelsUnlocked == 3 then
-- ... logic
end
end

setPersistentData(key, value)

Stores data in a cache for the world in which the script is running.

Parameters

  • key A string containing the key used to identify the data cache.
  • value The data to store in the cache.

Example

Stores the current level unlocked in the world, in this example, 5 levels are unlocked.

--... world code
World.setPersistentData("levelsUnlocked", 5)