Both sides previous revision Previous revision | |||
hpl2:amnesia:script_language_reference_and_guide:constants_and_enumerations [2013/01/15 04:42] thegreatcthulhu [Enumerations] |
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) |