spacer graphic
spacer graphic
Montage of games AGS Logo
spacer graphic

 

spacer graphic
Menu
spacer graphic Home
About
News
Features
Download AGS
spacer graphic Games 
Games main page
Award Winners
Picks of the month
Short games
Medium length games
Full length games
In Production
Hints & Tips
Community
Forums
AGSers World Map
Member websites
Chat
Resources
Tutorials
FAQ
Knowledge Base
Downloads
Links
AGS-related links
* AGS Manual
  * Scripting
    * Script language keywords

enum

Recommended for advanced users only

enum name {
option1 [ = value1 ],
option2 [ = value2 ],
...
};

Declares an enumeration type. An enumeration allows you to group together a set of related options, where only one will be true at any one time -- a bit like the contents of a list box.

For example, if you have a script function, doStuff, that can perform 3 different operations, you could do this:

function doStuff(int param) {
  if (param == 1) {
    // do something
  }
  else if (param == 2) {
    // do something else
  }
  // etc
}

but it's hard to read, and when calling the function from elsewhere in your script, it's not clear what 1 or 2 means. That's where enums come in:

enum DoStuffOption {
  BakeCake,
  DoLaundry
};

function doStuff(DoStuffOption param) { if (param == BakeCake) { // do something } else if (param == DoLaundry) { // do something else } // etc }

and then the calling code looks like:
doStuff(BakeCake);
thus making it perfectly clear what the command will do.

Normally, you would put the enum definition into the script header.

In summary, enums are not an essential part of scripting and you can get away perfectly well without using them, but in some specific situations they're very handy.


User comments and notes
There are currently no user comments on this page.
The user comment facility is currently disabled.