User Tools

Site Tools


hpl2:amnesia:script_language_reference_and_guide:constants_and_enumerations

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:amnesia:script_language_reference_and_guide:constants_and_enumerations [2013/01/13 23:35]
thegreatcthulhu
hpl2:amnesia:script_language_reference_and_guide:constants_and_enumerations [2015/10/06 21:06]
thegreatcthulhu [At a Glance]
Line 9: Line 9:
  
 **Constants** **Constants**
-<code c++> +<code c++>// Some math constants:
-// Some math constants:+
 const float PI = 3.1415926f; const float PI = 3.1415926f;
 const float E = 2.7182818f; const float E = 2.7182818f;
  
- +// Integer constants:
-// Integer constants: ​+
 // The constants in this example define when should collision events take place; // The constants in this example define when should collision events take place;
 // intended to be used with the AddEntityCollideCallback() engine function // intended to be used with the AddEntityCollideCallback() engine function
Line 28: Line 26:
  
 **Enumerated Constants (Enumerations)** **Enumerated Constants (Enumerations)**
-<code c++> +<code c++>enum Color     // Note: Enums are based on the int type.
-enum Color     // Note: Enums are based on the int type.+
 { {
     Red,        // has the default value of: 0     Red,        // has the default value of: 0
Line 35: Line 32:
     Blue        // value: (previous + 1) = 2, etc, if more added...     Blue        // value: (previous + 1) = 2, etc, if more added...
 } }
- 
  
 // Usage: // Usage:
Line 44: Line 40:
  
 // Assigning an integer value is not possible without an explicit conversion: // Assigning an integer value is not possible without an explicit conversion:
-Color col = 2;    // Causes compilation error! ​+Color col = 2;    // Causes compilation error!
  
-// Converting from integers - should generally be avoided: ​+// Converting from integers - should generally be avoided:
 Color col = Color(2); ​  // Assigns Blue to col, since 2 corresponds to Color::Blue Color col = Color(2); ​  // Assigns Blue to col, since 2 corresponds to Color::Blue
  
Line 54: Line 50:
 // This is allowed: // This is allowed:
 int colValue = col;   // so, enums can be passed to functions expecting ints --> see example below int colValue = col;   // so, enums can be passed to functions expecting ints --> see example below
- 
- 
  
 // Enumerations - choosing your own values // Enumerations - choosing your own values
Line 68: Line 62:
 AddEntityCollideCallback("​Player",​ "​Area_Example",​ "​ExampleCallback",​ false, CollisionState::​Both);​ AddEntityCollideCallback("​Player",​ "​Area_Example",​ "​ExampleCallback",​ false, CollisionState::​Both);​
  
- +// You can define all or some of the values; those left undefined will be
-// You can define all or some of the values; those left undefined will be +
 // assigned the value of previous_constant + 1 // assigned the value of previous_constant + 1
 enum Ending enum Ending
-   +{
     Good = 1,           // =   1     Good = 1,           // =   1
     ReallyGood, ​        // =   ​2 ​  ​(previous + 1)     ReallyGood, ​        // =   ​2 ​  ​(previous + 1)
Line 281: Line 274:
 // Later on: // Later on:
 HealingPotion vial = HealingPotion::​Small;​ HealingPotion vial = HealingPotion::​Small;​
-HealingPotion leatherArmor = BodyArmor::Small;+HealingPotion leatherArmor = BodyArmor::Weak;
  
  
Line 396: Line 389:
 As you can see, unlike the decimal number system, which represents all numbers using 10 different symbols (0-9), the HEX number system represents those same numbers using 16 different symbols (0-F). It just so happens that each of the HEX digits perfectly corresponds to one of all possible 4-bit combinations. Any one byte can thus be represented by 2 HEX digits - all you need to do is to refer to the table above, pick two hexadecimal digits, and write them together. To get the corresponding binary number, just replace the HEX digit with its binary equivalent from the table. As you can see, unlike the decimal number system, which represents all numbers using 10 different symbols (0-9), the HEX number system represents those same numbers using 16 different symbols (0-F). It just so happens that each of the HEX digits perfectly corresponds to one of all possible 4-bit combinations. Any one byte can thus be represented by 2 HEX digits - all you need to do is to refer to the table above, pick two hexadecimal digits, and write them together. To get the corresponding binary number, just replace the HEX digit with its binary equivalent from the table.
  
-Representing bytes using HEX system - some examples: 
 <​code>​ <​code>​
 +Representing bytes using HEX system - some examples:
 +
 +----------------------
 HEX          binary HEX          binary
 ---------------------- ----------------------
Line 406: Line 401:
  ​3A ​        0011 1010  ​3A ​        0011 1010
  ​FC ​        1111 1100  ​FC ​        1111 1100
 +----------------------
 </​code>​ </​code>​
  
hpl2/amnesia/script_language_reference_and_guide/constants_and_enumerations.txt · Last modified: 2015/10/06 21:06 by thegreatcthulhu