Difference between revisions of "HPL3/SOMA/Scripting/Sequences Helper"

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Jump to navigation Jump to search
(Add a sourced SOMA guide with explanations and stock-script examples.)
 
(Clarify the worked example using verified stock-script values.)
 
Line 6: Line 6:
  
 
== Follow the wake-up sequence ==
 
== Follow the wake-up sequence ==
−
The Tau Escape map stores one <code>cSequenceStatesData</code> object for this sequence and uses the sequence function’s own name in <code>Sequence_Begin</code>. Each <code>if / else if</code> condition selects a step. The delay belongs to the step that just ran: 0.25 before the sound step, then 6 before the fade-in step, then 5 before the timer step. <code>Sequence_End</code> completes the state check.
+
The Tau Escape map stores one <code>cSequenceStatesData</code> object for this sequence and uses the sequence function’s own name in <code>Sequence_Begin</code>. Each <code>if / else if</code> condition selects a step. The delay belongs to the step that just ran: 0.25 before the sound step, then 6 before the sequence finishes. <code>Sequence_End</code> completes the state check.
  
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
Line 17: Line 17:
 
{
 
{
 
Effect_Fade_Out(0);
 
Effect_Fade_Out(0);
−
Map_SetUnderwater(true);
 
−
 
−
Sound_SetGlobalVolume(0.0f, eSoundEntryType_WorldAll);
 
−
Sound_SetGlobalVolume(0.0f, eSoundEntryType_GuiWorld);
 
 
}
 
}
 
else if (Sequence_DoStepAndWait(6.0))
 
else if (Sequence_DoStepAndWait(6.0))
 
{
 
{
 +
Effect_Fade_In(5);
 
Sound_CreateAtEntity("WakeUp", "04_03_tau_escape/SFX/wake_up_sweet", "Player");
 
Sound_CreateAtEntity("WakeUp", "04_03_tau_escape/SFX/wake_up_sweet", "Player");
 
}
 
}
−
else if (Sequence_DoStepAndWait(5))
 
−
{
 
−
Effect_Fade_In(5);
 
−
 
−
Sound_FadeGlobalVolume(1.0f, 6.0f, eSoundEntryType_WorldAll);
 
−
Sound_FadeGlobalVolume(1.0f, 6.0f, eSoundEntryType_GuiWorld);
 
−
 
−
Emotion_StartBackgroundBreath(eBreathType_Normal, 06,1, 6,3, 5);
 
−
 
−
Effect_ImageTrail_Start(0.5, 0.1f, 6, 2);
 
−
CameraAnimation_Begin("WakeupAnim", "", true);
 
−
}
 
−
else if (Sequence_DoStepAndWait(5))
 
−
{
 
−
Map_AddTimer("SetupTravelTowardsTau", 0.3, "TimerSetupTravelTowardsTau");
 
−
}
 
−
 
 
Sequence_End();
 
Sequence_End();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
−
This is the stock Tau Escape sequence, including its sound, camera-animation and timer dependencies. The whole function is called again for each step, so code outside the step conditions also runs again.
+
This example is shortened from the stock Tau Escape sequence to demonstrate a fade-out followed by a sound and fade-in. Its wake-up sound must be available in the mod. The whole function is called again for each step, so code outside the step conditions also runs again.
  
 
== Include and adapt ==
 
== Include and adapt ==

Latest revision as of 14:24, 2 October 2026


The Sequences helper file in SOMA is script/helpers/helper_sequences.hps.

Sequence helpers divide an event function into ordered steps using a cSequenceStatesData object. Sequence_Begin prepares the state check, Sequence_DoStepAndWait runs one step and schedules the next, and Sequence_End resets a sequence after its steps finish. The source warns that the whole sequence function runs again for each step.

Follow the wake-up sequence

The Tau Escape map stores one cSequenceStatesData object for this sequence and uses the sequence function’s own name in Sequence_Begin. Each if / else if condition selects a step. The delay belongs to the step that just ran: 0.25 before the sound step, then 6 before the sequence finishes. Sequence_End completes the state check.

cSequenceStatesData mSeqWakeUp;
		void Seq_WakeUp(const tString &in asX)
		{
			Sequence_Begin("Seq_WakeUp", mSeqWakeUp);
			 
			if (Sequence_DoStepAndWait(0.25))
			{
				Effect_Fade_Out(0);
			}
			else if (Sequence_DoStepAndWait(6.0))
			{
				Effect_Fade_In(5);
				Sound_CreateAtEntity("WakeUp", "04_03_tau_escape/SFX/wake_up_sweet", "Player");
			}
			Sequence_End();
		}

This example is shortened from the stock Tau Escape sequence to demonstrate a fade-out followed by a sound and fade-in. Its wake-up sound must be available in the mod. The whole function is called again for each step, so code outside the step conditions also runs again.

Include and adapt

  1. Include helpers/helper_sequences.hps alongside the helpers needed by the actions in your sequence.
  2. Keep a separate cSequenceStatesData object for the sequence and pass it to Sequence_Begin.
  3. Put each action inside a Sequence_DoStepAndWait condition, keeping the if / else if chain and the final Sequence_End().

See also