TombEngine/Documentation/doc/1 modules/Logic.html
Lwmte 7c2f6f96e4
Lua API documentation revisions (#1636)
* First iteration

* Revise Moveable class documentation

* Revise remaining documentation

* Extend laraType description

* Enum documentation revisions

* Edit version

* Corrections and updates

* Corrections
2025-04-20 22:39:30 +03:00

561 lines
22 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>TombEngine 1.8.2 Lua API</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>&nbsp;TombEngine</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>1 Modules</h2>
<ul class="nowrap">
<li> <a href="../1 modules/Effects.html">Effects</a></li>
<li> <a href="../1 modules/Flow.html">Flow</a></li>
<li> <a href="../1 modules/Input.html">Input</a></li>
<li> <a href="../1 modules/Inventory.html">Inventory</a></li>
<li> <here>Logic</here></li>
<li> <a href="../1 modules/Objects.html">Objects</a></li>
<li> <a href="../1 modules/Sound.html">Sound</a></li>
<li> <a href="../1 modules/Strings.html">Strings</a></li>
<li> <a href="../1 modules/Util.html">Util</a></li>
<li> <a href="../1 modules/View.html">View</a></li>
</ul>
<h2>2 Classes</h2>
<ul class="nowrap">
<li> <a href="../2 classes/Collision.Probe.html">Collision.Probe</a></li>
<li> <a href="../2 classes/Flow.Level.html">Flow.Level</a></li>
<li> <a href="../2 classes/Flow.Settings.html">Flow.Settings</a></li>
<li> <a href="../2 classes/Flow.Statistics.html">Flow.Statistics</a></li>
<li> <a href="../2 classes/Objects.AIObject.html">Objects.AIObject</a></li>
<li> <a href="../2 classes/Objects.Camera.html">Objects.Camera</a></li>
<li> <a href="../2 classes/Objects.LaraObject.html">Objects.LaraObject</a></li>
<li> <a href="../2 classes/Objects.Moveable.html">Objects.Moveable</a></li>
<li> <a href="../2 classes/Objects.Room.html">Objects.Room</a></li>
<li> <a href="../2 classes/Objects.Sink.html">Objects.Sink</a></li>
<li> <a href="../2 classes/Objects.SoundSource.html">Objects.SoundSource</a></li>
<li> <a href="../2 classes/Objects.Static.html">Objects.Static</a></li>
<li> <a href="../2 classes/Objects.Volume.html">Objects.Volume</a></li>
<li> <a href="../2 classes/Strings.DisplayString.html">Strings.DisplayString</a></li>
<li> <a href="../2 classes/View.DisplaySprite.html">View.DisplaySprite</a></li>
</ul>
<h2>3 Primitive Classes</h2>
<ul class="nowrap">
<li> <a href="../3 primitive classes/Flow.Fog.html">Flow.Fog</a></li>
<li> <a href="../3 primitive classes/Flow.Horizon.html">Flow.Horizon</a></li>
<li> <a href="../3 primitive classes/Flow.InventoryItem.html">Flow.InventoryItem</a></li>
<li> <a href="../3 primitive classes/Flow.LensFlare.html">Flow.LensFlare</a></li>
<li> <a href="../3 primitive classes/Flow.SkyLayer.html">Flow.SkyLayer</a></li>
<li> <a href="../3 primitive classes/Flow.Starfield.html">Flow.Starfield</a></li>
<li> <a href="../3 primitive classes/Color.html">Color</a></li>
<li> <a href="../3 primitive classes/Rotation.html">Rotation</a></li>
<li> <a href="../3 primitive classes/Time.html">Time</a></li>
<li> <a href="../3 primitive classes/Vec2.html">Vec2</a></li>
<li> <a href="../3 primitive classes/Vec3.html">Vec3</a></li>
</ul>
<h2>4 Enums</h2>
<ul class="nowrap">
<li> <a href="../4 enums/Collision.MaterialType.html">Collision.MaterialType</a></li>
<li> <a href="../4 enums/Effects.BlendID.html">Effects.BlendID</a></li>
<li> <a href="../4 enums/Effects.EffectID.html">Effects.EffectID</a></li>
<li> <a href="../4 enums/Effects.StreamerFeatherMode.html">Effects.StreamerFeatherMode</a></li>
<li> <a href="../4 enums/Effects.ParticleAnimationType.html">Effects.ParticleAnimationType</a></li>
<li> <a href="../4 enums/Flow.ErrorMode.html">Flow.ErrorMode</a></li>
<li> <a href="../4 enums/Flow.FreezeMode.html">Flow.FreezeMode</a></li>
<li> <a href="../4 enums/Flow.GameStatus.html">Flow.GameStatus</a></li>
<li> <a href="../4 enums/Input.ActionID.html">Input.ActionID</a></li>
<li> <a href="../4 enums/Objects.AmmoType.html">Objects.AmmoType</a></li>
<li> <a href="../4 enums/Objects.HandStatus.html">Objects.HandStatus</a></li>
<li> <a href="../4 enums/Objects.WeaponType.html">Objects.WeaponType</a></li>
<li> <a href="../4 enums/Objects.MoveableStatus.html">Objects.MoveableStatus</a></li>
<li> <a href="../4 enums/Objects.ObjID.html">Objects.ObjID</a></li>
<li> <a href="../4 enums/Objects.RoomFlagID.html">Objects.RoomFlagID</a></li>
<li> <a href="../4 enums/Objects.RoomReverb.html">Objects.RoomReverb</a></li>
<li> <a href="../4 enums/Sound.SoundTrackType.html">Sound.SoundTrackType</a></li>
<li> <a href="../4 enums/Strings.DisplayStringOption.html">Strings.DisplayStringOption</a></li>
<li> <a href="../4 enums/Util.LogLevel.html">Util.LogLevel</a></li>
<li> <a href="../4 enums/View.AlignMode.html">View.AlignMode</a></li>
<li> <a href="../4 enums/View.CameraType.html">View.CameraType</a></li>
<li> <a href="../4 enums/View.PostProcessMode.html">View.PostProcessMode</a></li>
<li> <a href="../4 enums/View.ScaleMode.html">View.ScaleMode</a></li>
</ul>
<h2>5 Lua utility modules</h2>
<ul class="nowrap">
<li> <a href="../5 lua utility modules/CustomBar.html">CustomBar</a></li>
<li> <a href="../5 lua utility modules/Diary.html">Diary</a></li>
<li> <a href="../5 lua utility modules/EventSequence.html">EventSequence</a></li>
<li> <a href="../5 lua utility modules/Timer.html">Timer</a></li>
<li> <a href="../5 lua utility modules/Type.html">Type</a></li>
</ul>
</div>
<div id="content">
<h1>Table <code>Logic</code></h1>
<p>Saving data, triggering functions, and callbacks for level-specific scripts.</p>
<p>
</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#AddCallback">AddCallback(point, func)</a></td>
<td class="summary">Register a function as a callback.</td>
</tr>
<tr>
<td class="name" ><a href="#RemoveCallback">RemoveCallback(point, func)</a></td>
<td class="summary">Deregister a function as a callback.</td>
</tr>
<tr>
<td class="name" ><a href="#HandleEvent">HandleEvent(name, type, [activator])</a></td>
<td class="summary">Attempt to find an event set and execute a particular event from it.</td>
</tr>
<tr>
<td class="name" ><a href="#EnableEvent">EnableEvent(name, type)</a></td>
<td class="summary">Attempt to find an event set and enable specified event in it.</td>
</tr>
<tr>
<td class="name" ><a href="#DisableEvent">DisableEvent(name, type)</a></td>
<td class="summary">Attempt to find an event set and disable specified event in it.</td>
</tr>
</table>
<h2><a href="#Special_objects">Special objects </a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#Lara">Lara</a></td>
<td class="summary">An <a href="../2 classes/Objects.Moveable.html#">Objects.Moveable</a> entry representing Lara herself.</td>
</tr>
</table>
<h2><a href="#Special_tables">Special tables </a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#LevelVars">LevelVars</a></td>
<td class="summary">A table with level-specific data which will be saved and loaded.</td>
</tr>
<tr>
<td class="name" ><a href="#GameVars">GameVars</a></td>
<td class="summary">A table with game data which will be saved and loaded.</td>
</tr>
<tr>
<td class="name" ><a href="#LevelFuncs">LevelFuncs</a></td>
<td class="summary">A table nested table system for level-specific functions.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "AddCallback"></a>
<strong>AddCallback(point, func)</strong>
</dt>
<dd>
Register a function as a callback.
<p>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 <code>OnStart</code>, <code>OnLoad</code>, etc. in their level script.</p>
<p>Possible values for <code>point</code>:</p>
<pre class="example"><span class="comment">-- These take functions which accept no arguments
</span>PRE_START <span class="comment">-- will be called immediately before OnStart
</span>POST_START <span class="comment">-- will be called immediately after OnStart
</span>
PRE_SAVE <span class="comment">-- will be called immediately before OnSave
</span>POST_SAVE <span class="comment">-- will be called immediately after OnSave
</span>
PRE_LOAD <span class="comment">-- will be called immediately before OnLoad
</span>POST_LOAD <span class="comment">-- will be called immediately after OnLoad
</span>
PRE_FREEZE <span class="comment">-- will be called before entering freeze mode
</span>POST_FREEZE <span class="comment">-- will be called immediately after exiting freeze mode
</span>
<span class="comment">-- These take a LevelEndReason arg, like OnEnd
</span>PRE_END <span class="comment">-- will be called immediately before OnEnd
</span>POST_END <span class="comment">-- will be called immediately after OnEnd
</span>
<span class="comment">-- These take functions which accepts a deltaTime argument
</span>PRE_LOOP <span class="comment">-- will be called in the beginning of game loop
</span>POST_LOOP <span class="comment">-- will be called at the end of game loop
</span>
<span class="comment">-- These take functions which accepts an objectNumber argument, like OnUseItem
</span>PRE_USE_ITEM <span class="comment">-- will be called immediately before OnUseItem
</span>POST_USE_ITEM <span class="comment">-- will be called immediately after OnUseItem
</span></pre>
<p>The order in which two functions with the same CallbackPoint are called is undefined.
i.e. if you register <code>MyFunc</code> and <code>MyFunc2</code> with <code>PRELOOP</code>, both will be called in the beginning of game loop, but there is no guarantee that <code>MyFunc</code> will be called before <code>MyFunc2</code>, or vice-versa.</p>
<p>Any returned value will be discarded.</p>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">point</span>
<span class="types"><span class="type">CallbackPoint</span></span>
When should the callback be called?
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">LevelFunc</span></span>
The function to be called (must be in the <a href="../1 modules/Logic.html#LevelFuncs">LevelFuncs</a> hierarchy). Will receive, as an argument, the time in seconds since the last frame.
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">LevelFuncs.MyFunc = <span class="keyword">function</span>(dt) <span class="global">print</span>(dt) <span class="keyword">end</span>
TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRELOOP, LevelFuncs.MyFunc)</pre>
</ul>
</dd>
<dt>
<a name = "RemoveCallback"></a>
<strong>RemoveCallback(point, func)</strong>
</dt>
<dd>
Deregister a function as a callback.
Will have no effect if the function was not registered as a callback
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">point</span>
<span class="types"><span class="type">CallbackPoint</span></span>
The callback point the function was registered with. See <a href="../1 modules/Logic.html#AddCallback">AddCallback</a>
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">LevelFunc</span></span>
The function to remove; must be in the LevelFuncs hierarchy.
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRELOOP, LevelFuncs.MyFunc)</pre>
</ul>
</dd>
<dt>
<a name = "HandleEvent"></a>
<strong>HandleEvent(name, type, [activator])</strong>
</dt>
<dd>
Attempt to find an event set and execute a particular event from it.
<p>Possible event type values:</p>
<pre class="example">ENTER
INSIDE
LEAVE
LOAD
SAVE
START
END
LOOP
USE_ITEM
MENU</pre>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
Name of the event set to find.
</li>
<li><span class="parameter">type</span>
<span class="types"><span class="type">EventType</span></span>
Event to execute.
</li>
<li><span class="parameter">activator</span>
<span class="types"><a class="type" href="../2 classes/Objects.Moveable.html#">Moveable</a></span>
Optional activator.
<em>Default: Lara.</em>
</li>
</ul>
</dd>
<dt>
<a name = "EnableEvent"></a>
<strong>EnableEvent(name, type)</strong>
</dt>
<dd>
Attempt to find an event set and enable specified event in it.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
Name of the event set to find.
</li>
<li><span class="parameter">type</span>
<span class="types"><span class="type">EventType</span></span>
Event to enable.
</li>
</ul>
</dd>
<dt>
<a name = "DisableEvent"></a>
<strong>DisableEvent(name, type)</strong>
</dt>
<dd>
Attempt to find an event set and disable specified event in it.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
Name of the event set to find.
</li>
<li><span class="parameter">type</span>
<span class="types"><span class="type">EventType</span></span>
Event to disable.
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Special_objects"></a>Special objects </h2>
<dl class="function">
<dt>
<a name = "Lara"></a>
<strong>Lara</strong>
</dt>
<dd>
An <a href="../2 classes/Objects.Moveable.html#">Objects.Moveable</a> entry representing Lara herself.
</dd>
</dl>
<h2 class="section-header has-description"><a name="Special_tables"></a>Special tables </h2>
<div class="section-description">
TombEngine uses the following tables for specific things.
</div>
<dl class="function">
<dt>
<a name = "LevelVars"></a>
<strong>LevelVars</strong>
</dt>
<dd>
A table with level-specific data which will be saved and loaded.
This is for level-specific information that you want to store in saved games.
<p>For example, you may have a level with a custom puzzle where Lara has
to kill exactly seven enemies to open a door to a secret. You could use
the following line each time an enemy is killed:</p>
<pre class="example">LevelVars.enemiesKilled = LevelVars.enemiesKilled + <span class="number">1</span></pre>
<p>If the player saves the level after killing three, saves, and then reloads the save
some time later, the values <code>3</code> will be put back into <code>LevelVars.enemiesKilled.</code></p>
<p><strong>This table is emptied when a level is finished.</strong> If the player needs to be able
to return to the level (like in the Karnak and Alexandria levels in <em>The Last Revelation</em>),
you will need to use the <a href="../1 modules/Logic.html#GameVars">GameVars</a> table, below.</p>
<p><strong>LevelVars.Engine is a reserved table used internally by TombEngine's libs. Do not modify, overwrite, or add to it.</strong></p>
</dd>
<dt>
<a name = "GameVars"></a>
<strong>GameVars</strong>
</dt>
<dd>
A table with game data which will be saved and loaded.
This is for information not specific to any level, but which concerns your whole
levelset or game, that you want to store in saved games.
<p>For example, you may wish to have a final boss say a specific voice line based on
a choice the player made in a previous level. In the level with the choice, you could
write:</p>
<pre class="example">GameVars.playerSnoopedInDrawers = <span class="keyword">true</span></pre>
<p>And in the script file for the level with the boss, you could write:</p>
<pre class="example"><span class="keyword">if</span> GameVars.playerSnoopedInDrawers <span class="keyword">then</span>
PlayAudioTrack(<span class="string">"how_dare_you.wav"</span>)
<span class="keyword">end</span></pre>
<p>Unlike <a href="../1 modules/Logic.html#LevelVars">LevelVars</a>, this table will remain intact for the entirety of the game.</p>
<p><strong>GameVars.Engine is a reserved table used internally by TombEngine's libs. Do not modify, overwrite, or add to it.</strong></p>
</dd>
<dt>
<a name = "LevelFuncs"></a>
<strong>LevelFuncs</strong>
</dt>
<dd>
A table nested table system for level-specific functions.
<p>This serves a few purposes: it holds the level callbacks (listed below) as well as
any trigger functions you might have specified. For example, if you give a trigger
a Lua name of "my_trigger" in Tomb Editor, you will have to implement it as a member
of this table:</p>
<pre class="example">LevelFuncs.my_trigger = <span class="keyword">function</span>()
<span class="comment">-- implementation goes here
</span><span class="keyword">end</span></pre>
<p>You can organise functions into tables within the hierarchy:</p>
<pre class="example">LevelFuncs.enemyFuncs = {}
LevelFuncs.enemyFuncs.makeBaddyRunAway = <span class="keyword">function</span>()
<span class="comment">-- implementation goes here
</span><span class="keyword">end</span>
LevelFuncs.enemyFuncs.makeBaddyUseMedkit = <span class="keyword">function</span>()
<span class="comment">-- implementation goes here
</span><span class="keyword">end</span></pre>
<p>There are two special subtables which you should <strong>not</strong> overwrite:</p>
<pre class="example">LevelFuncs.Engine <span class="comment">-- this is for 'first-party' functions, i.e. ones that come with TombEngine.
</span>LevelFuncs.External <span class="comment">-- this is for 'third-party' functions. If you write a library providing LevelFuncs functions for other builders to use in their levels, put those functions in LevelFuncs.External.YourLibraryNameHere
</span></pre>
<p>
<p>The following are the level callbacks. They are optional; if your level has no special
behaviour for a particular scenario, you do not need to implement the function. For
example, if your level does not need any special initialisation when it is loaded,
you can just leave out <code>LevelFuncs.OnStart</code>.</p>
<p><strong>The order of loading is as follows:</strong></p>
<ol>
<li>The level data itself is loaded.</li>
<li>The level script itself is run (i.e. any code you put outside the <a href="../1 modules/Logic.html#LevelFuncs">LevelFuncs</a> callbacks is executed).</li>
<li>Save data is loaded, if saving from a saved game (will empty <a href="../1 modules/Logic.html#LevelVars">LevelVars</a> and <a href="../1 modules/Logic.html#GameVars">GameVars</a> and repopulate them with what they contained when the game was saved).</li>
<li>If loading from a save, <code>OnLoaded</code> will be called. Otherwise, <code>OnStart</code> will be called.</li>
<li>The control loop, in which <code>OnLoop</code> will be called once per frame, begins.</li>
</ol>
</p>
<h3>Fields:</h3>
<ul>
<li><span class="parameter">OnStart</span>
<span class="types"><span class="type">function</span></span>
Will be called when a level is entered by completing a previous level or by selecting it in the menu. Will not be called when loaded from a saved game.
</li>
<li><span class="parameter">OnLoad</span>
<span class="types"><span class="type">function</span></span>
Will be called when a saved game is loaded, just <em>after</em> data is loaded
</li>
<li><span class="parameter">OnLoop</span>
<span class="types"><span class="type">function(float)</span></span>
Will be called during the game's update loop,
and provides the delta time (a float representing game time since last call) via its argument.
</li>
<li><span class="parameter">OnSave</span>
<span class="types"><span class="type">function</span></span>
Will be called when the player saves the game, just <em>before</em> data is saved
</li>
<li><span class="parameter">OnEnd</span>
<span class="types"><span class="type">function</span></span>
<p>(EndReason) Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level. It can take an <code>EndReason</code> arg:</p>
<pre><code>EXIT_TO_TITLE
LEVEL_COMPLETE
LOAD_GAME
DEATH
OTHER
</code></pre>
<p>For example:</p>
<pre><code>LevelFuncs.OnEnd = function(reason)
if(reason == TEN.Logic.EndReason.DEATH) then
print("death")
end
end
</code></pre>
</li>
<li><span class="parameter">OnUseItem</span>
<span class="types"><span class="type">function</span></span>
Will be called when using an item from inventory.
</li>
<li><span class="parameter">OnFreeze</span>
<span class="types"><span class="type">function</span></span>
Will be called when any of the Freeze modes are activated.
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="https://github.com/hispidence/TEN-LDoc">TEN-LDoc</a> (a fork of <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a>)</i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>