Difference between revisions of "HPL3/SOMA/Getting Started/Add Your First Script"

From Frictional Wiki
Jump to navigation Jump to search
(Created page with "{{Hpl3SomaGettingStarted|step=5}} Every map can have a map script. For the sample map, it is <code>sample_map.hps</code> beside <code>sample_map.hpm</code>. == Add a visible...")
 
 
Line 3: Line 3:
 
Every map can have a map script. For the sample map, it is <code>sample_map.hps</code> beside <code>sample_map.hpm</code>.
 
Every map can have a map script. For the sample map, it is <code>sample_map.hps</code> beside <code>sample_map.hpm</code>.
  
== Add a visible script change ==
+
{{note|It is highly recoomended to use Visual Studio Code with the HPL3 Language Tools extension for scripting.}}
  
# Open <code>MyFirstMod/maps/sample_map/sample_map.hps</code> in your text editor.
+
==Add a visible script change==
# Find <code>void OnStart()</code> inside the <code>cScrMap</code> class.
+
 
# Add the debug-message call between its braces:
+
#Open <code>MyFirstMod/maps/sample_map/sample_map.hps</code> in your text editor.
 +
#Find <code>void OnStart()</code> inside the <code>cScrMap</code> class.
 +
#Add the debug-message call between its braces:
  
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
Line 16: Line 18:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
# Save the script.
+
#Save the script.
# Launch the mod. If the map was already running in development mode, press <code>F5</code> to reload it.
+
#Launch the mod. If the map was already running in development mode, press <code>F5</code> to reload it.
  
 
The text <code>Hello World!</code> should appear at the lower-left of the screen when the map starts.
 
The text <code>Hello World!</code> should appear at the lower-left of the screen when the map starts.
Line 23: Line 25:
 
{{note|Keep the generated includes, the <code>cScrMap : iScrMap</code> declaration, and the surrounding callback structure. This tutorial changes only the body of <code>OnStart()</code>.}}
 
{{note|Keep the generated includes, the <code>cScrMap : iScrMap</code> declaration, and the surrounding callback structure. This tutorial changes only the body of <code>OnStart()</code>.}}
  
== Checkpoint ==
+
==Checkpoint==
  
 
Continue when the message appears in-game after a fresh map start.
 
Continue when the message appears in-game after a fresh map start.
  
== If it does not work ==
+
==If it does not work==
  
* Confirm the script has the same base name and folder as the map: <code>sample_map.hpm</code> and <code>sample_map.hps</code>.
+
*Confirm the script has the same base name and folder as the map: <code>sample_map.hpm</code> and <code>sample_map.hps</code>.
* Confirm the line ends with a semicolon and uses straight quotation marks.
+
*Confirm the line ends with a semicolon and uses straight quotation marks.
* Confirm you edited the script inside your copied mod.
+
*Confirm you edited the script inside your copied mod.
* Press <code>F1</code> in development mode, then use '''Show Error List''' or '''Show HPL Log'''.
+
*Press <code>F1</code> in development mode, then use '''Show Error List''' or '''Show HPL Log'''.
  
 
Read [[HPL3/Scripting/Scripting Guide/Scripting Workflow and Structure|Scripting Workflow and Structure]] for the generated map-script layout and [[HPL3/Scripting/Scripting Guide/Hello World|Hello World]] for the focused scripting lesson.
 
Read [[HPL3/Scripting/Scripting Guide/Scripting Workflow and Structure|Scripting Workflow and Structure]] for the generated map-script layout and [[HPL3/Scripting/Scripting Guide/Hello World|Hello World]] for the focused scripting lesson.

Latest revision as of 12:55, 31 August 2026

Every map can have a map script. For the sample map, it is sample_map.hps beside sample_map.hpm.

Note icon.png It is highly recoomended to use Visual Studio Code with the HPL3 Language Tools extension for scripting.

Add a visible script change

  1. Open MyFirstMod/maps/sample_map/sample_map.hps in your text editor.
  2. Find void OnStart() inside the cScrMap class.
  3. Add the debug-message call between its braces:
void OnStart()
{
    cLux_AddDebugMessage("Hello World!");
}
  1. Save the script.
  2. Launch the mod. If the map was already running in development mode, press F5 to reload it.

The text Hello World! should appear at the lower-left of the screen when the map starts.

Note icon.png Keep the generated includes, the cScrMap : iScrMap declaration, and the surrounding callback structure. This tutorial changes only the body of OnStart().

Checkpoint

Continue when the message appears in-game after a fresh map start.

If it does not work

  • Confirm the script has the same base name and folder as the map: sample_map.hpm and sample_map.hps.
  • Confirm the line ends with a semicolon and uses straight quotation marks.
  • Confirm you edited the script inside your copied mod.
  • Press F1 in development mode, then use Show Error List or Show HPL Log.

Read Scripting Workflow and Structure for the generated map-script layout and Hello World for the focused scripting lesson.