Difference between revisions of "HPL3/Scripting/Scripting Guide/Sequences"

From Frictional Wiki
Jump to navigation Jump to search
(Created page with "{{wip}} {{Hpl3ScriptingGuideMenuBasic}} {{shortPageTitle}} Many of the events that happen throughout Rebirth are triggered sequences - a sound plays, then the player's FoV ch...")
 
Line 3: Line 3:
 
{{shortPageTitle}}
 
{{shortPageTitle}}
  
Many of the events that happen throughout Rebirth are triggered sequences - a sound plays, then the player's FoV changes, then a light starts flashing etc. etc.  
+
Many of the events that happen inside map script files are triggered sequences. For example: A sound plays, then the player's FoV changes, then a light starts flashing, etc.
  
 
We control all of those through a set of wrappers we call Sequences, which hide a bunch of timers away and make things easier to read.  
 
We control all of those through a set of wrappers we call Sequences, which hide a bunch of timers away and make things easier to read.  
Line 11: Line 11:
 
For each sequence you need a map property to store the state - a cSequenceStatesData property e.g.
 
For each sequence you need a map property to store the state - a cSequenceStatesData property e.g.
  
*shows viewer*
+
<pre>cSequenceStatesData mSequenceAlert;</pre>
  
 
Then you create a sequence function. This will be repeatedly called until the whole sequence is over. It looks something like this:
 
Then you create a sequence function. This will be repeatedly called until the whole sequence is over. It looks something like this:
Line 17: Line 17:
 
*shows sequence example*
 
*shows sequence example*
  
As you can see, Sequence_DoStepAndPause() in there actually pauses the whole sequence until some external event - in this case the callback from the voice playing code - calls SequenceStates_Resume() and asks it to continue.
+
As you can see, <code>Sequence_DoStepAndPause()</code> in there actually pauses the whole sequence until some external event - in this case the callback from the voice playing code - calls <code>SequenceStates_Resume()</code> and asks it to continue.
  
To start the sequence, you just call the sequence function once with an empty argument when you want it to trigger e.g.
+
To start the sequence, you just call the sequence function once with an empty argument when you want it to trigger:
 +
 
 +
Sequence_Alert("");
  
 
No need to call it every frame or anything! Once started, timers will automatically make sure that the sequence steps get followed when they need to be.
 
No need to call it every frame or anything! Once started, timers will automatically make sure that the sequence steps get followed when they need to be.
  
Since sequences are totally independent of each other, you could run multiple sequences in parallel, but it can get very confusing, so I wouldn’t recommend it.
+
{{tip|Since sequences are totally independent of each other, you could run multiple sequences in parallel.}}
 +
 
 +
== See Also ==
 +
* [[HPL3/Scripting/Sequences_Helper|Sequences Helper]]
  
  

Revision as of 15:49, 12 August 2020


Many of the events that happen inside map script files are triggered sequences. For example: A sound plays, then the player's FoV changes, then a light starts flashing, etc.

We control all of those through a set of wrappers we call Sequences, which hide a bunch of timers away and make things easier to read.

They are very useful when we need to handle a big amount of timers that should occur one after another - or in other words - a sequence.

For each sequence you need a map property to store the state - a cSequenceStatesData property e.g.

cSequenceStatesData mSequenceAlert;

Then you create a sequence function. This will be repeatedly called until the whole sequence is over. It looks something like this:

  • shows sequence example*

As you can see, Sequence_DoStepAndPause() in there actually pauses the whole sequence until some external event - in this case the callback from the voice playing code - calls SequenceStates_Resume() and asks it to continue.

To start the sequence, you just call the sequence function once with an empty argument when you want it to trigger:

Sequence_Alert("");

No need to call it every frame or anything! Once started, timers will automatically make sure that the sequence steps get followed when they need to be.

Icon tip.png Tip: Since sequences are totally independent of each other, you could run multiple sequences in parallel.

See Also



Timers