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.
|