• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Enum error

A

anomalous

Guest
Just starting using enums (had been using all macros) This is in a script on create to define colors:

enum color
{
r_red = c_red,
r_yellow = c_yellow
}

compile error is line3: enum expression must be an integer constant

as far as I know c_red = 255, but regardless I changed it to 255, still doesn't work.
Must be an obvious error.
 

jo-thijs

Member
I just tried that exact code and it works just fine for me.

Do you have the latest vesion of GM:S?
Have you tried clearing the cache?
Have you tried it in a different project?
 
A

anomalous

Guest
Indeed, thanks for checking.

Line 4 was actually the issue (line after the one reported), it looked like this:
m_purple = make_color_rgb(131,25,80),

Which appears to be what's failing. I thought make color was integer?

I show debug message on m_purple (as a variable not enum), and it prints:
COLOR = 14058722 (an integer?)

to be sure I did this:
y1 = round(make_color_rgb(226,132,214));
enum color
{
m_purple = y1
}

Same error.
 
F

Fuzenrad

Guest
{
r_red = c_red,
r_yellow = c_yellow
}

compile error is line3: enum expression must be an integer constant.
It has a comma after c_red. Leave the lines with nothing, or with ; (semicolon).

EDIT:
Code:
m_purple = make_color_rgb(131,25,80),
The same for the second code you posted, without this comma it will work okay.
 
F

Fuzenrad

Guest
Dude, you're using enum in the wrong way, see this.

Enums
An enum is an "enumerator", and it essentially permits you to create your own limited data type with a list of constant values. Enums are global scope variables (this is implicit, and they require no "global" suffix orglobalvar declaration) and they have the following structure:

enum <variable>{<constant> [= <value>]}

In the following example, we create an enum for the colours of the rainbow and assign it various constants and default values:

Code:
enum rainbowcolors {
red,
orange,
yellow,
green,
blue,
indigo,
violet
}
The enum entries can only be real numbers or expressions with previous enums, and by default are numbered from 0 upwards, so our example given above would default to red = 0, orange = 1, yellow = 2, etc... You can also assign values to the enum variables at the time of creation, using real numbers or expressions:

Code:
enum rainbowcolors {
red = 5,
orange = 5 * 2,
yellow = 15,
green = 20,
blue = 25,
indigo = 30,
violet = 35 * enum_test.entry
}
Notice in the above example we use another enum to create an expression for "violet". This only works if the enum being referenced was created before the enum that is using it in an expression, but it will not work for variables or functions, since the enum value must be able to be evaluated as a constant on compile.

To later access the value within a given enum type, you can use the point "." method, like this:

Code:
var value = rainbowcolours.green;
Note that you cannot modify the values for any enum constant after it has been created.
 
A

anomalous

Guest
@jo-thijs

I thought any number in GMS was a constant, they are all also highlighted in red (any number typed)

I can convert to hex, but it seems silly, I'll just go back to variables for colors, much easier.
Thanks figuring it out.
 

jo-thijs

Member
No, constants are things of which the compiler can read the value at compile time.
make_color_rgb is a function that needs to run during run time.

If you don't want to use hexadecimal representation, you can also use:
131 + 25 * 256 + 80 * 65536

@Fuzenrad, I guess you're right.
Macro constants would be more appropriate, but it's still a perfectly legit way to use enums.
 
Top