- Home /
negatives value in an enum, constant? how to set a negative value
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.
Answer by Dracorat · Apr 10, 2013 at 06:08 PM
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.
Answer by fafase · Apr 10, 2013 at 05:50 PM
Actually you cannot use negative value with Javascript.
You can in C# though as enum are int internally. But Js does not allow.
Your answer
Follow this Question
Related Questions
Enumerated Colors 2 Answers
Flag structure variable in unity editor 1 Answer
hashtable: snapshot out of sync 2 Answers
Enum to int issue 1 Answer
GUI Enum Dropdown 2 Answers