Enumeration
Enumeration is a concept used in the DOM, GOM, and HeroScript, of predefining (enumerating) a list of predefined values. Enumerated values are defined in the DOM, and then used in GOM node fields. They can be manipulated with both HeroScript and the CLI.
These are essentially the same as ENUMs in C++, C#, etc.
Possible types of enumerated values would be the the seasons of a year, the different flood states a river could be in, and so forth.
To create an enumeration, the following steps are required via the CLI:
- Make an enumeration definition
- Add values to the definition
- Create a field which uses that definition
When created, the default value of an enumeration will be the first enumerated value.
Contents |
Example
// Create Enumeration Definition : ced "river_states"; "empty" "full" //Modify Enumeration Definition, Add Values : medav "river_states"; "empty" "mostly_empty" "half_full" "full" //Create a field definition : cfd "river_size", enum "river_states"; description="River's water level"
Converting enum values to string
Enumerations auto-convert to strings in HeroScript, to be displayed or used in other ways. For example:
enumVar as enum coolPeople enumVar = Bryan println(enumVar)
Related functions
This is a server and client side external function:
function GetEnumValues(enumName as String) as List of String
This function returns a string list of the values of the enum (the assigned predefined values)
list = GetEnumValues("river_states" would have list equal to ("empty", "mostly_empty", "half_full", "full")
String Utils: Change Case
You can automatically convert the _ in the enums to spaces and also capitalize the first letter of the words.
var newWord = strutils:changeCase(ourEnum, EVERYWORDCAP)
The result of ourEnum being equal to mostly_empty will result in a string return of Mostly Empty. This is very handy for using enums in gui elements on the client side or comparing results inputed from a command.