Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision |
4rpl:commands:func_awake [2023/06/10 17:33] – Karsten75 | 4rpl:commands:func_awake [2025/02/14 14:57] (current) – external edit 127.0.0.1 |
---|
'':Awake'' is called whenever a unit with this script attached is created. This can happen at game load, or during a game when a unit is created with [[4rpl:commands:createunit|CreateUnit]]. | '':Awake'' is called whenever a unit with this script attached is created. This can happen at game load, or during a game when a unit is created with [[4rpl:commands:createunit|CreateUnit]]. |
| |
For Global Control scripts, '':Awake'' runs during a game frame, either before units are processed (for the Pre- phase) or after units are processed (for the Post- phase). Here, both '':Awake'' and [[4rpl:commands:once|:Once]] run alongside each other, and depending on whether the script is marked to run while paused or not, both of them will run either during a paused frame or an unpaused frame. Because of this, '':Awake'' in Global Control scripts will always run after '':Awake'' in units. Key difference between '':Awake'' and '':Once'' remains where '':Awake'' will run again when the map is loaded, but '':Once'' will not. | Please refer to [[cw4:Programming Notes]] for an in-depth discussion and comparison between ''[[func_Once| :Once]]'', ''[[func_GameLoaded|:GameLoaded]]'', and ''[[func_Awake|:Awake]]''. |
| |
==== Awake and Once in Unit and Global Control scripts ==== | |
| |
Execution order of Global Control scripts which run while paused: \\ | |
{{awake_order_1.png }} | |
<WRAP clear></WRAP> | |
Execution order of Global Control scripts which do not run while paused: \\ | |
{{awake_order_2.png }} | |
| |
==== Technical explanation ==== | |
A critical distinction exists between scripts attached to units and scripts scheduled to run during Pre- or Post- phases of Global Control. | |
| |
Functionally, the '':Awake'' function in pre- or Post Global Control phases are equivalent to a ''[[func_once|:Once]]'' function. It is not executed until the appropriate moment in processing (before or after all units are processed for every game tick). This may cause execution of '':Awake'' functions to appear in the incorrect order, where each unit will execute it's '':Awake'' function as it is instantiated during map load (either initial load or load from a save, there is no difference), and the '':Awake'' in a Global Control script will execute at the beginning or end, respectively, of a game tick. | |
| |
===== Examples ===== | ===== Examples ===== |