Scripting

Examples

Script doors, levers, Areas, conversations and module events in Luau. Everything here is generated from the engine, so it matches the build it describes.

LuauProfile rpg.script/559 entries · generated from the engine

Area enter lights

Attach to an Area in Module editor. Tag its light placements "arrival_lamp". Area self has properties, but no placement lights.

area_enter_lights.luauluau
-- Attach to an Area in Module editor. Tag its light placements "arrival_lamp".
-- Area self has properties, but no placement lights.
local light_effect = { tags = {"arrival_lamp"} }

function OnEnter(character)
    local objects = Area.FindByTag("arrival_lamp")
    for i = 1, #objects do
        local lights = objects[i]:GetLights()
        for j = 1, #lights do lights[j].Enabled = true end
    end
end

function OnExit(character)
    local objects = Area.FindByTag("arrival_lamp")
    for i = 1, #objects do
        local lights = objects[i]:GetLights()
        for j = 1, #lights do lights[j].Enabled = false end
    end
end

Door opened lights

Attach to a Door Script component. Tag target light placements "door_lamp". Engine-read names must keep their spelling.

door_opened_lights.luauluau
-- Attach to a Door Script component. Tag target light placements "door_lamp".
-- Engine-read names must keep their spelling.
local light_effect = { tags = {"door_lamp"} }

function OnOpened(user)
    local objects = Area.FindByTag("door_lamp")
    for i = 1, #objects do
        local lights = objects[i]:GetLights()
        for j = 1, #lights do
            lights[j].Enabled = not lights[j].Enabled
        end
    end
end

-- Empty lifecycle success still completes durably.
function OnClosed(user)
end

Lever torches

exported_properties / light_effect / OnUsed are read by the engine: do not rename them. Light-only OnUsed: every tagged Light and the lever's optional lamp toggle.

lever_torches.luauluau
-- exported_properties / light_effect / OnUsed are read by the engine: do not rename them.
-- Light-only OnUsed: every tagged Light and the lever's optional lamp toggle.
local exported_properties = {
    target_tag = { type = "string", default = "crypt_torch" },
}
local light_effect = { tags = { "$target_tag" }, self = true }

function OnUsed(user)
    local objects = Area.FindByTag(self:GetProperty("target_tag") :: string)
    for i = 1, #objects do
        -- Self is handled once below even if the author also tags the lever.
        if objects[i] ~= self then
            local lights = objects[i]:GetLights()
            for j = 1, #lights do
                lights[j].Enabled = not lights[j].Enabled
            end
        end
    end
    local lamps = self:GetLights()
    for i = 1, #lamps do
        lamps[i].Enabled = not lamps[i].Enabled
    end
end

Module start

Attach to the Module Script card. Inspect the isolated play save's owner counter.

module_start.luauluau
-- Attach to the Module Script card. Inspect the isolated play save's owner counter.
function OnModuleStart()
    local starts = GetUses() + 1
    if IsFirstStart() then starts = 1 end
    SetUses(starts)
    PublishUses(starts)
end