User Tools

Site Tools


hpl2:amnesia:script_language_reference_and_guide:execution_flow

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:amnesia:script_language_reference_and_guide:execution_flow [2012/12/20 19:49]
thegreatcthulhu
hpl2:amnesia:script_language_reference_and_guide:execution_flow [2012/12/21 21:51] (current)
thegreatcthulhu
Line 1: Line 1:
-====== Execution ​flow ======+====== Execution ​Flow ======
  
  
 This section describes at which points in time the game engine transfers execution to and from the user-supplied script functions. This section describes at which points in time the game engine transfers execution to and from the user-supplied script functions.
  
-The game itself is executed by the system running the game engine code, that is, the binary game code written by the developers, and embedded inside the game's executable files. Amnesia supports scripting by allowing you to associate each level with a corresponding script file (mapname.hps).+The game itself is executed by the system running the game engine code, that is, the binary game code written by the developers, and embedded inside the game's executable files. Amnesia supports scripting by allowing you to associate each level with a corresponding script file (//mapname//.hps).
 On a conceptual level, as the game runs, at certain points the control is transferred to the script engine, which executes the user-supplied script, making level-specific things happen, before returning the control back to the game (which takes care of all the rest). On a conceptual level, as the game runs, at certain points the control is transferred to the script engine, which executes the user-supplied script, making level-specific things happen, before returning the control back to the game (which takes care of all the rest).
  
 By default, there are only 3 events where this happens. These are listed below: By default, there are only 3 events where this happens. These are listed below:
-  * level start – this happens when the level is first loaded,+  * level start – this happens ​once, when the level is first loaded,
   * level enter – this occurs whenever the player (re)enters the level (the player might be allowed to backtrack),   * level enter – this occurs whenever the player (re)enters the level (the player might be allowed to backtrack),
   * level leave – this occurs on level transition, when the player leaves one level to enter another.   * level leave – this occurs on level transition, when the player leaves one level to enter another.
Line 17: Line 17:
   * OnLeave()   * OnLeave()
  
-A well-formed ​script file must have at least one of these functions implemented, although they can be empty (i.e. they do nothing). As the game runs, and a map is loaded, on these level events the control is handed over to the corresponding functions, and they are executed (see the image). By default, these 3 events are the only points in time where this happens.+Normally, a script file will have at least one of these functions implemented. As the game runs, and a map is loaded, on these level events the control is handed over to the corresponding functions, and they are executed (see the image). By default, these 3 events are the only points in time where this happens.
  
 {{ :​hpl2:​amnesia:​script_language_reference_and_guide:​exflow_img1.jpg?​nolink |}} {{ :​hpl2:​amnesia:​script_language_reference_and_guide:​exflow_img1.jpg?​nolink |}}
Line 29: Line 29:
 <code c++>void OnEnter() <code c++>void OnEnter()
 { {
 +    // Note: The 3rd parameter is the callback function, defined below.
     AddTimer("​internal.timer.id",​ 10.0f, "​MyFunc"​);​     AddTimer("​internal.timer.id",​ 10.0f, "​MyFunc"​);​
 } }
Line 51: Line 52:
 void OnEnter() void OnEnter()
 { {
-    // Note: The 3rd parameter is the callback function, defined below. 
     AddTimer("​internal.timer.id",​ 5.0f, "​MyFunc"​);  ​     AddTimer("​internal.timer.id",​ 5.0f, "​MyFunc"​);  ​
 } }
hpl2/amnesia/script_language_reference_and_guide/execution_flow.1356032998.txt.gz · Last modified: 2012/12/20 19:49 by thegreatcthulhu