Talow
Sorceror
Enums are a wonderful way of referencing integers without having to remember the number this can help with a few different things.
There are other instances where Enums are called but that is the easiest to show.
Enums are in essence ints that you can reference with words and that's why you love them!
To create an enum is simple in this example we'll use days of the week:
Lets look at some important things with this.
Firstly: we didn't identify what values the words would be relating to, and so it starts at a value of 0.
meaning that Days.Sat would equal 0 and then Days.Sun would equal 1 ext.
You can declare the value for your words simply too...
and so forth however if your values are going in order you only have to specify the first value.
now that you have the enum set up you can declare a variable for it pretty easily too...
Further more you can use it in if statements or in a switch statement...
if later on you need to use the integer value of your Enum you can do so simply with conversion...
I hope that gives you guys ideas for furthering your scripts to new heights.
There are other instances where Enums are called but that is the easiest to show.
Enums are in essence ints that you can reference with words and that's why you love them!
To create an enum is simple in this example we'll use days of the week:
Code:
enum Days {
Sat,
Sun,
Mon,
Tue,
Wed,
Thu,
Fri
};
Lets look at some important things with this.
Firstly: we didn't identify what values the words would be relating to, and so it starts at a value of 0.
meaning that Days.Sat would equal 0 and then Days.Sun would equal 1 ext.
You can declare the value for your words simply too...
Code:
enum Days {
Sat = 1,
Sun = 2,
...
}
now that you have the enum set up you can declare a variable for it pretty easily too...
Code:
Days dayofweek = Days.sat;
Further more you can use it in if statements or in a switch statement...
Code:
if(dayofweek ==Days.sun) {
console.write("the variable 'dayofweek' equals SUNDAY!");
}
Code:
switch (dayofweek)
{
case Days.sat: {
console.write("saturday");
break;
}
default: {
console.write("It's not saturday");
break;
}
}
if later on you need to use the integer value of your Enum you can do so simply with conversion...
Code:
int x = (int)Days.Sun;
int y = (int)dayofweek;