Lua utility module EventSequence

Event sequence - a chain of functions to call at specified times, modeled after TRNG's organizers.

Example usage:

local EventSequence = require("EventSequence")

-- These will be called by the sequence
LevelFuncs.HealLara = function()
    Lara:SetHP(Lara:GetHP()+10)
end

local nSpawned = 0
LevelFuncs.SpawnBaddy = function(baddy, name, pos)
    local myBaddy = TEN.Objects.Moveable(baddy, name..nSpawned, pos, nil, 0)
    myBaddy:Enable()
    nSpawned = nSpawned + 1
end

-- This function triggers the sequence
LevelFuncs.TriggerSequence = function(obj)
    local posSteve = TEN.Objects.GetMoveableByName("stevePosNullmesh"):GetPosition()
    local posChris = TEN.Objects.GetMoveableByName("chrisPosNullmesh"):GetPosition()
    local mySeq = EventSequence.Create("my_seq",
        false, -- does not loop
        {seconds = true, deciseconds = true}, -- timer format, see Timer for details
        6, -- seconds until call the function specified in next arg
        "HealLara", -- first function to call. If we don't need to pass any arguments, we can just give the func name as a string
        2.1, -- seconds until the next function, after the previous one has been called
        {"SpawnBaddy", TEN.Objects.ObjID.BADDY1, "steve", posSteve}, -- if we DO want to pass arguments to the function to be called, we give a table with the name of the function ("SpawnBaddy" in this case) followed by the args to pass to it
        0.5,
        {"SpawnBaddy", TEN.Objects.ObjID.SAS_CAIRO, "chris", posChris},
        1,
        "HealLara")

    -- event sequences are inactive to begin with and so need to be started
    mySeq:Start()
end

-- EventSequence runs on Timer, so this call is required
LevelFuncs.OnControlPhase = function(dt)
    Timer.UpdateAll(dt)
end

Functions

Create(name, loop, timerFormat[, ...]) Create (but do not start) a new event sequence.
Get(name) Get an event sequence by its name.
mySequence:SetPaused(p) Pause or unpause the sequence.
mySequence:IsPaused() Get whether or not the sequence is paused
mySequence:Start() Begin or unpause a sequence.
mySequence:Stop() Stop the sequence.
mySequence:IsActive() Get whether or not the sequence is active


Functions

Create(name, loop, timerFormat[, ...])
Create (but do not start) a new event sequence.

Parameters:

  • name string A label to give the sequence; used to retrieve the timer later as well as internally by TEN.
  • loop bool if true, the sequence will start again from its first timer once its final function has been called
  • timerFormat table or bool same as in Timer. This is mainly for debugging. This will not work properly if another sequence or timer is showing a countdown.
  • ... a variable number of pairs of arguments - a time in seconds, followed by the function (must be defined in the LevelFuncs table) to call once the time has elapsed, followed by another duration in seconds, another function name, etc. You can specify a function either by its name as a string, or by a table with the function name as the first member, followed by its arguments (see above example). (optional)

Returns:

    The inactive sequence.
Get(name)
Get an event sequence by its name.

Parameters:

  • name string The label that was given to the sequence when it was created

Returns:

    The sequence
mySequence:SetPaused(p)
Pause or unpause the sequence. If showing the remaining time on-screen, its color will be set to yellow (paused) or white (unpaused).

Parameters:

  • p bool if true, the sequence will be paused; if false, it will be unpaused
mySequence:IsPaused()
Get whether or not the sequence is paused

Returns:

    true if the timer is paused, false if otherwise
mySequence:Start()
Begin or unpause a sequence. If showing the remaining time on-screen, its color will be set to white.
mySequence:Stop()
Stop the sequence.
mySequence:IsActive()
Get whether or not the sequence is active

Returns:

    true if the sequence is active, false if otherwise
generated by LDoc 1.4.6 Last updated 2022-08-11 22:43:52