TombEngine/Documentation/doc/5 lua utility modules/Timer.html
TrainWrack e0b50439b3
Custom bar module (#1492)
* Update to bug report form

* Update bug_report.yaml

* Update AUTHORS.md

- Tomo (general coding, special FX coding, bug fixing)

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update bug_report.yaml

* Add files via upload

* Update CHANGELOG.md

* Add files via upload

* Update CustomBar.lua

* Fix bugs with bar property setters

* Update CustomBar.lua

* Update documentation

---------

Co-authored-by: Stranger1992 <84292688+Stranger1992@users.noreply.github.com>
Co-authored-by: Nemoel-Tomo <tomo_669@hotmail.com>
Co-authored-by: Jakub <kubabilinski03@gmail.com>
Co-authored-by: Jakub <80340234+Jakub768@users.noreply.github.com>
Co-authored-by: Lwmte <3331699+Lwmte@users.noreply.github.com>
2025-03-09 06:59:49 +02:00

552 lines
17 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.7.2 (Developer) 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> <a href="../1 modules/Logic.html">Logic</a></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.FeatherMode.html">Effects.FeatherMode</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> <here>Timer</here></li>
<li> <a href="../5 lua utility modules/Type.html">Type</a></li>
</ul>
</div>
<div id="content">
<h1>Lua utility module <code>Timer</code></h1>
<p>Basic timer - after a specified number of seconds, the specified thing happens.</p>
<p>
<p> Timers are updated automatically every frame before OnLoop.</p>
<p> Example usage:</p>
<pre>
<span class="keyword">local</span> Timer = <span class="global">require</span>(<span class="string">"Engine.Timer"</span>)
<span class="comment">-- This will be called when the timer runs out
</span>LevelFuncs.FinishTimer = <span class="keyword">function</span>(healthWhenStarted, victoryMessage)
<span class="comment">-- Open a door, display a message, make an explosion... whatever you wish
</span> DoSomething(healthWhenStarted, victoryMessage)
<span class="keyword">end</span>
<span class="comment">-- This function triggers the timer
</span>
LevelFuncs.TriggerTimer = <span class="keyword">function</span>(obj)
<span class="keyword">local</span> myTimer = Timer.Create(<span class="string">"my_timer"</span>,
<span class="number">5.0</span>,
<span class="keyword">false</span>,
{minutes = <span class="keyword">false</span>, seconds = <span class="keyword">true</span>, deciseconds = <span class="keyword">true</span>},
LevelFuncs.FinishTimer,
Lara:GetHP(),
<span class="string">"Well done!"</span>)
myTimer:Start()
<span class="keyword">end</span>
</pre>
</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" ><a href="#Create">Create(name, totalTime, loop, timerFormat, func[, ...])</a></td>
<td class="summary">Create (but do not start) a new timer.</td>
</tr>
<tr>
<td class="name" ><a href="#Get">Get(name)</a></td>
<td class="summary">Get a timer by its name.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:SetFunction">myTimer:SetFunction(func[, ...])</a></td>
<td class="summary">Give the timer a new function and args</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:Start">myTimer:Start()</a></td>
<td class="summary">Begin or unpause a timer.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:Stop">myTimer:Stop()</a></td>
<td class="summary">Stop the timer.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:IsActive">myTimer:IsActive()</a></td>
<td class="summary">Get whether or not the timer is active</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:SetPaused">myTimer:SetPaused(p)</a></td>
<td class="summary">Pause or unpause the timer.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:IsPaused">myTimer:IsPaused()</a></td>
<td class="summary">Get whether or not the timer is paused</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:GetRemainingTime">myTimer:GetRemainingTime()</a></td>
<td class="summary">Get the remaining time for a timer.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:SetRemainingTime">myTimer:SetRemainingTime(remainingTime)</a></td>
<td class="summary">Set the remaining time for a timer</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:GetTotalTime">myTimer:GetTotalTime()</a></td>
<td class="summary">Get the total time for a timer.</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:SetTotalTime">myTimer:SetTotalTime(totalTime)</a></td>
<td class="summary">Set the total time for a timer</td>
</tr>
<tr>
<td class="name" ><a href="#myTimer:SetLooping">myTimer:SetLooping(looping)</a></td>
<td class="summary">Set whether or not the timer loops</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "Create"></a>
<strong>Create(name, totalTime, loop, timerFormat, func[, ...])</strong>
</dt>
<dd>
Create (but do not start) a new timer. </p>
<p> You have the option of displaying the remaining time on the clock. Timer format details:
<p>
</p>
<pre class="example"><span class="comment">-- deciseconds are 1/10th of a second
</span>
<span class="comment">-- mins:secs
</span><span class="keyword">local</span> myTimeFormat1 = {minutes = <span class="keyword">true</span>, seconds = <span class="keyword">true</span>, deciseconds = <span class="keyword">false</span>}
<span class="comment">-- also mins:secs
</span><span class="keyword">local</span> myTimeFormat2 = {minutes = <span class="keyword">true</span>, seconds = <span class="keyword">true</span>}
<span class="comment">-- secs:decisecs
</span><span class="keyword">local</span> myTimeFormat3 = {seconds = <span class="keyword">true</span>, deciseconds = <span class="keyword">true</span>}
<span class="comment">-- secs; also what is printed if you pass true instead of a table
</span><span class="keyword">local</span> myTimeFormat4 = {seconds = <span class="keyword">true</span>}</pre>
<p>Use this sparingly; in the classics, timed challenges did not have visible countdowns. For shorter timers, the gameplay benefit from showing the remaining time might not be necessary, and could interfere with the atmosphere of the level.</p>
<p>At any given time, only one timer can show its countdown.</p>
<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>
A label to give this timer; used to retrieve the timer later. <strong>Do not give your timers a name beginning with __TEN, as this is reserved for timers used by other internal libaries</strong>.
</li>
<li><span class="parameter">totalTime</span>
<span class="types"><span class="type">number</span></span>
The duration of the timer, in seconds
</li>
<li><span class="parameter">loop</span>
<span class="types"><span class="type">bool</span></span>
if true, the timer will start again immediately after the time has elapsed
</li>
<li><span class="parameter">timerFormat</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.6">table</a> or <span class="type">bool</span></span>
If a table is given, the remaining time will be shown as a string, formatted according to the values in the table. If true, the remaining seconds, rounded up, will show at the bottom of the screen. If false, the remaining time will not be shown on screen.
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">func</span></span>
The LevelFunc function to call when the time is up
</li>
<li><span class="parameter">...</span>
a variable number of arguments with which the above function will be called
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../5 lua utility modules/Timer.html#">Timer</a></span>
The timer in its paused state
</ol>
</dd>
<dt>
<a name = "Get"></a>
<strong>Get(name)</strong>
</dt>
<dd>
Get a timer by its name.
<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>
The label that was given to the timer when it was created
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../5 lua utility modules/Timer.html#">Timer</a></span>
The timer
</ol>
</dd>
<dt>
<a name = "myTimer:SetFunction"></a>
<strong>myTimer:SetFunction(func[, ...])</strong>
</dt>
<dd>
Give the timer a new function and args
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
The LevelFunc member to call when the time is up
</li>
<li><span class="parameter">...</span>
a variable number of arguments with which the above function will be called
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "myTimer:Start"></a>
<strong>myTimer:Start()</strong>
</dt>
<dd>
Begin or unpause a timer. If showing the remaining time on-screen, its color will be set to white.
</dd>
<dt>
<a name = "myTimer:Stop"></a>
<strong>myTimer:Stop()</strong>
</dt>
<dd>
Stop the timer.
</dd>
<dt>
<a name = "myTimer:IsActive"></a>
<strong>myTimer:IsActive()</strong>
</dt>
<dd>
Get whether or not the timer is active
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">bool</span></span>
true if the timer is active, false if otherwise
</ol>
</dd>
<dt>
<a name = "myTimer:SetPaused"></a>
<strong>myTimer:SetPaused(p)</strong>
</dt>
<dd>
Pause or unpause the timer. If showing the remaining time on-screen, its color will be set to yellow (paused) or white (unpaused).
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">p</span>
<span class="types"><span class="type">bool</span></span>
if true, the timer will be paused; if false, it would be unpaused
</li>
</ul>
</dd>
<dt>
<a name = "myTimer:IsPaused"></a>
<strong>myTimer:IsPaused()</strong>
</dt>
<dd>
Get whether or not the timer is paused
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">bool</span></span>
true if the timer is paused, false if otherwise
</ol>
</dd>
<dt>
<a name = "myTimer:GetRemainingTime"></a>
<strong>myTimer:GetRemainingTime()</strong>
</dt>
<dd>
Get the remaining time for a timer.
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">float</span></span>
the time in seconds remaining on the clock
</ol>
</dd>
<dt>
<a name = "myTimer:SetRemainingTime"></a>
<strong>myTimer:SetRemainingTime(remainingTime)</strong>
</dt>
<dd>
Set the remaining time for a timer
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">remainingTime</span>
<span class="types"><span class="type">number</span></span>
the new time remaining for the timer
</li>
</ul>
</dd>
<dt>
<a name = "myTimer:GetTotalTime"></a>
<strong>myTimer:GetTotalTime()</strong>
</dt>
<dd>
Get the total time for a timer.
This is the amount of time the timer will start with, as well as when starting a new loop
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">float</span></span>
the timer's total time
</ol>
</dd>
<dt>
<a name = "myTimer:SetTotalTime"></a>
<strong>myTimer:SetTotalTime(totalTime)</strong>
</dt>
<dd>
Set the total time for a timer
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">totalTime</span>
<span class="types"><span class="type">number</span></span>
timer's new total time
</li>
</ul>
</dd>
<dt>
<a name = "myTimer:SetLooping"></a>
<strong>myTimer:SetLooping(looping)</strong>
</dt>
<dd>
Set whether or not the timer loops
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">looping</span>
<span class="types"><span class="type">bool</span></span>
whether or not the timer loops
</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>