Is there a way to check a variable against the enumeration
selector value? I have a feeling when referencing enumerations in scripts I can only get the display value, but I hope I'm wrong.
E.G.
Code: Select all
...
if (someVariable == VariableEnumeration.SOME_ENUMERATION) {
// do stuff...
}
...
This warns me about a Signed/Unsigned mismatch, but still compiles. I'll admit I haven't tested this, the fact that it warns me of this made me move on to try something else.
I thought that this might work, and I get no warnings.
Code: Select all
...
int localVariable;
smRead(VariableEnumerations.SOME_ENUMERATION, localVariable);
if (someVariable == localVariable) {
// do stuff...
}
...
However when running this I get unexpected results, and it looks like it might be taking the ascii hex values of the enumeration display value and then casting that into a double (the result is a very large number). I read in another forum that the color displays convert all variables to doubles which would explain this.
Long story short, with my testing I don't see a way to check a variable against an enumeration selector value, which is unfortunate because I really don't like the ambiguity of the following. This also opens up the possibility of changing the enumerations selector values and breaking the script.
Code: Select all
...
if (someVariable == 0) { // VariableEnumerations.SOME_ENUMERATION
// do stuff...
}
...
I'm hoping I'm missing something, which is usually the case, I'd love to be able to use case statements with the enumeration selector values but trying that opened up another can of worms and I couldn't get anything to compile (case statements must be constant, signed/unsigned error again, etc.).