Table Logic
Saving data, triggering functions, and callbacks for level-specific scripts.
Functions
| AddCallback(point, func) | Register a function as a callback. |
| RemoveCallback(point, func) | Deregister a function as a callback. |
| HandleEvent(name, type, [activator]) | Attempt to find an event set and execute a particular event from it. |
| EnableEvent(name, type) | Attempt to find an event set and enable specified event in it. |
| DisableEvent(name, type) | Attempt to find an event set and disable specified event in it. |
Functions
- AddCallback(point, func)
-
Register a function as a callback.
This is intended for module/library developers who want their modules to do stuff during level start/load/end/save/control phase, but don't want the level designer to add calls to
OnStart,OnLoad, etc. in their level script. Any returned value will be discarded.Note: the order in which two functions with the same CallbackPoint are called is undefined.
i.e. if you register
MyFuncandMyFunc2withPRE_LOOP, both will be called in the beginning of game loop, but there is no guarantee thatMyFuncwill be called beforeMyFunc2, or vice-versa.Arguments:
The callbacks
PRE_END,POST_END,PRE_USE_ITEM, andPOST_USE_ITEMreceive an argument (like their respective LevelFuncs.OnEnd and LevelFuncs.OnUseItem).The argument for
PRE_LOOPandPOST_LOOPis deprecated and should not be used.
Parameters:
- point CallbackPoint When should the callback be called?
- func function The function to be called (must be in the LevelFuncs hierarchy). Will receive, as an argument, the time in seconds since the last frame.
Usage:
LevelFuncs.MyFunc = function() -- do stuff here end TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRE_START, LevelFuncs.MyFunc) -- Another example, with argument LevelFuncs.OnLevelEnd = function(reason) -- do stuff here print("Level ended because reason code: " .. reason) end TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRE_END, LevelFuncs.OnLevelEnd) -- Another example, two functions added in the same callback type LevelFuncs.FuncA = function() -- do stuff here end LevelFuncs.FuncB = function() -- do other stuff here end TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.POST_LOAD, LevelFuncs.FuncA) TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.POST_LOAD, LevelFuncs.FuncB) -- In this case, both FuncA and FuncB will be called after level load, but the order is undefined.
- RemoveCallback(point, func)
-
Deregister a function as a callback.
Will have no effect if the function was not registered as a callback
Parameters:
- point CallbackPoint The callback point the function was registered with. See AddCallback
- func function The function to remove; must be in the LevelFuncs hierarchy.
Usage:
TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRELOOP, LevelFuncs.MyFunc)
- HandleEvent(name, type, [activator])
-
Attempt to find an event set and execute a particular event from it.
Parameters:
- name string Name of the event set to find.
- type EventType Event to execute.
- activator Moveable Optional activator. Default: Lara.
Usage:
-- Executes the "ENTER" volume event of the event set named "MyVolumeEvent" TEN.Logic.HandleEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER) -- Executes the "LOAD" global event of the event set named "MyGlobalEvent", with enemy as activator enemy = TEN.Objects.GetMoveableByName("MyEnemy") TEN.Logic.HandleEvent("MyGlobalEvent", TEN.Logic.EventType.LOAD, enemy)
- EnableEvent(name, type)
-
Attempt to find an event set and enable specified event in it.
Parameters:
Usage:
-- Enables the "ENTER" volume event of the event set named "MyVolumeEvent" TEN.Logic.EnableEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER)
- DisableEvent(name, type)
-
Attempt to find an event set and disable specified event in it.
Parameters:
Usage:
-- Disables the "ENTER" volume event of the event set named "MyVolumeEvent" TEN.Logic.DisableEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER)