Task

From LuaSTG Wiki
Jump to navigation Jump to search
Task
Task.png
Task Icon
Location Task Tab

A task node allows the execution of the block of code it contains to be paused for some time period. Task is a handy tool for writing code that are executed each frame on game objects.


Usage[edit | edit source]

A task has to be associated with a game object on creation. A game object can have zero or more tasks.

All the tasks of all game objects in the game will be executed (as if) in parallel. However, note that there is an order in which those tasks will be executed, which is dependent on the implementation of LuaSTG data. As a result, the order of execution cannot be manually re-arranged in a script.

When a task is executed each frame, it has to be eventually paused in order for other tasks to continue execution. This is done by a call to the coroutine.yield() function (or a Wait node, which essentially uses coroutine.yield() in its implementation). After a call to the function, the task will stop execution in the current frame, and continue from the line after the one that the task stopped at (which is immediately following coroutine.yield()) on the next frame.

A brand new task may not get executed in the exact frame it is created. Usually it will be executed starting from the next frame instead.


Code[edit | edit source]

A task node will get translated to "lasttask = task.New(self, function() ... end)", where ... is the content of the task.


Known Issue[edit | edit source]

A task will be marked as "dead" when the code execution reaches the bottom of the task. However, a task will never actually gets deleted until its associated game object is deleted or the task is deleted manually. This will lead to unwanted slow down of the game if too many tasks are put under one unit. This is present on LuaSTG ex+0.81c. See Ltask.lua which caused this issue.