GMS 2 colour_get_hue returns float?


Hi !

colour_get_hue, colour_get_saturation, colour_get_value seem to be returning float numbers.
In the manual it says int. I would expect int 0-255. Is there a reason for it to be a float?

The colour_get_red, colour_get_green, colour_get_blue seem to return ints

As an example I have a col = 7220112 and colour_get_hue returns 226.806945800781.
var _col = make_color_hsv( 227, 178, 144 );
var _hue = colour_get_hue( _col );

show_debug_message( "_hue = " + string( _hue ) );
I mean I will probably just write a wrapper to do it for me, just curious if that had an intended reason or was a bug.


The 226.8 is probably a bit rounding error from the 227 you gave it.

The color you create has three properties: hue, saturation, and value (hence HSV). The function colour_get_hue only returns the HUE part. You would have to query colour_get_saturation or colour_get_value for the other two.

I personally prefer creating colors in RGB instead (red, green, blue.) You can query the red, green, and/or blue parts from such a color as well.

[EDIT] Sorry, I read the rest of your question and it looks like you already understand this.
My best guess is that when creating colors in HSV instead of RGB, maybe the program has to interpolate to the nearest valid value, hence the floats.


Forum Staff
Numeric values are internally stored as floats. This may be a result of float imprecision, as extracting one part of this triplet may involve multiplication or other inaccurate-for-floating-points mathematical operations.