waskar
1
Hi there,
I want to set a negative value in an enumeration, but it seams not to be possible, i would like to set -1 for left as so:
enum face
{
LEFT = -1, // error: no negatives values
RIGHT = 1,
}
public function Start() : void {
facing = face.DROITE;
do you now a way to make it work? is there a way to set up CONSTANTS?
thank you.
2 Answers
2
fafase
2
Actually you cannot use negative value with Javascript.
You can in C# though as enum are int internally. But Js does not allow.
You can use the offset trick.
In short, figure out the largest possible negative value. Let’s say it’s -100.
Make each value of the enum 100 higher.
Create a function to get the enum’s value. In the function, subtract 100 from the enum’s actual value.