Difference between revisions of "Lua Code Loops"

Jump to navigation Jump to search
11 bytes added ,  01:07, 21 November 2021
m
no edit summary
(basic code for easy management of multiple looping functions)
 
m
Line 1: Line 1:
To make code loops in Lua that last more than one frame, you must redefine a function the game already calls every frame, and put the code in that. So far it is known that Tick() from Tick.lua and ProcessDebugKeys() from DebugKeys.lua will loop every frame, starting once the game finishes loading at startup.
To make code loops in Lua that last more than one frame, you must redefine a function the game already calls every frame, and put the code in that. So far it is known that Tick() from Tick.lua and ProcessDebugKeys() from DebugKeys.lua will loop every frame, starting once the game finishes loading at startup.


Here is a way to do that so you only need to actually redefine an existing function once, and then to manage multiple looping things, you just create/delete tables that define loop functions and their persistent variables:
Here is a way to do that so you only need to actually redefine an existing function once, and then to manage multiple looping things, you just create/delete tables that define individual loop functions and their persistent variables:
{{Collapse|1=<pre>
{{Collapse|1=<pre>
-- empty table to put all loop tables in
-- empty table to put all loop tables in

Navigation menu