User Tools

Site Tools


hpl2:amnesia:script_language_reference_and_guide:variables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:amnesia:script_language_reference_and_guide:variables [2012/12/28 01:55]
thegreatcthulhu
hpl2:amnesia:script_language_reference_and_guide:variables [2012/12/30 01:44] (current)
thegreatcthulhu [Discussion]
Line 134: Line 134:
 </​code>​ </​code>​
  
-<note tip>​Since the engine exposes the SetGlobalVar//​Typename//​() & SetLocalVar//​Typename//​() functions (and their Add- and Get- counterparts) for seting //game variables//,​ where the terms global and local have a slightly different meaning ​then what was presented here for //script variables//,​ here's a table that explains how these predefined functions and script-declared variables compare:</​note>​+<note tip>​Since the engine exposes the SetGlobalVar//​Typename//​() & SetLocalVar//​Typename//​() functions (and their Add- and Get- counterparts) for seting //game variables//,​ where the terms global and local have a slightly different meaning ​than what was presented here for //script variables//,​ here's a table that explains how these predefined functions and script-declared variables compare:</​note>​
  
 {{ :​hpl2:​amnesia:​script_language_reference_and_guide:​variablescope_table.jpg?​direct |}} {{ :​hpl2:​amnesia:​script_language_reference_and_guide:​variablescope_table.jpg?​direct |}}
  
-<note tip>The functions which manipulate global game variables, SetGlobalVar//​Typename//​(),​ AddGlobalVar//​Typename//​() and GetGlobalVar//​Typename//​() [where //​Typename//​ can be either Int, Float, or String], provide a way for you to store and use a value in a storage location which is maintained for the duration of your game (or custom story). It can be accessed from more than one map script, and any changes in one map will be visible from the others. They are global //relative to the maps//.+<note tip>The functions which manipulate global game variables, SetGlobalVar//​Typename//​(),​ AddGlobalVar//​Typename//​() and GetGlobalVar//​Typename//​() [where //​Typename//​ can be either Int, Float, or String], provide a way for you to store and use a value in a storage location which is maintained for the duration of your game (or custom story). It can be accessed from more than one map script, and any changes ​made in one map will be visible from the others. They are global //relative to the maps//.</​note>​
  
-Functions which manipulate local game variables, SetLocalVar//​Typename//​(),​ AddLocalVar//​Typename//​() and GetLocalVar//​Typename//​(),​ allow you to define and use storage locations for the current map script. They are visible from every part of the map script, once set for the first time. So they are //local to that particular map script// (cant use them from a different map), but are //global relative to functions// in that script. In this respect, they are similar to the script variables declared globally (outside any function, or code block).</​note>​+<note tip>Functions which manipulate local game variables, SetLocalVar//​Typename//​(),​ AddLocalVar//​Typename//​() and GetLocalVar//​Typename//​(),​ allow you to define and use storage locations for the current map script. They are visible from every part of the map script, once set for the first time. So they are //local to that particular map script// (can'​t ​use them from a different map), but are //global relative to functions// in that script. In this respect, they are similar to the script variables declared globally (outside any function, or code block).</​note>​
  
 === Simultaneous Declarations === === Simultaneous Declarations ===
Line 151: Line 151:
 <​code>​int a = 1, b = 2; <​code>​int a = 1, b = 2;
 int x = 5, y;</​code>​ int x = 5, y;</​code>​
 +
 +
 +=== Using Variables to Help Others (And Yourself!) ===
 +
 +Those of you who write code snippets, or even longer scripts, for your fellow forum members can use variables to make your code easier to use and understand. ​
 +Often, the same name or value appears in several places. Also, the script usually contains a lot of placeholder values, and when the person you are helping takes over the code, a lot of these placeholder values need to be replaced by the ones which are adequate in the context of their custom story or full conversion. The replacement process can be tedious and error prone, but variables come to the rescue (although search & replace tools can mitigate the problem).
 +
 +Instead of hard coding the names and values, you can assign them to variables at the beginning of your script, and then use variables instead.
 +This way, if any changes need to be made, it only needs to happen in //one place// - at the start, where the variable declarations are. This eliminates the need to dig through the code, trying to find every single appearance of some value.
 +
 +Also, remember to give your variables descriptive names, so that others (and you) can quickly figure out what are they used for!
 +You can indicate where the placeholder values should be replaced with a comment or two.
 +
 +<code c++>
 +// Example: Fictional Help-Script
 +// -----------------------------------
 +
 +// Replace these assignments to match the names in your map
 +string scriptArea_jumpScare1 = "​Area_JumpScare1";​
 +string scriptArea_jumpScare2 = "​Area_JumpScare2";​
 +string scriptArea_startMusic = "​Area_StartMusic";​
 +string scriptArea_lookAtTarget = "​Area_LookAt";​
 +string particleSys_Orbs = "​PS_Orbs";​
 +
 +// You can adjust these values as well, if you want
 +float screenFadeInTime = 6.0f;
 +float musicFadeInTime = 3.5f;
 +
 +// ...
 +
 +// Here goes the code that uses the variables above (omitted).
 +// Note: the script would use a variable wherever the corresponding value would otherwise appear. E.g.:
 +// FadeIn(screenFadeInTime); ​        // ---> instead of the hard-coded FadeIn(6.0f);​
 +
 +// ...
 +</​code>​
  
  
hpl2/amnesia/script_language_reference_and_guide/variables.1356659708.txt.gz ยท Last modified: 2012/12/28 01:55 by thegreatcthulhu