(I read the first two comments, and I don't really understand why do you talk about image_speed when OP is asking about decimals in image_index.)
So: How come image_index appear to have decimals?
I think it is to do with rounding error (precision loss), a common issue with "real number" (double-precision floating-point number, 8 bytes, a.k.a.
double) in computing, apparently in GML, every number you have in GML code is a
double (real number).
To help illustrate it for you:
Code:
// 90 * 0.1 = 9.0? Right? or not...
repeat (90)
{
image_index = image_index + 0.1;
}
show_message(string_format(image_index, 32, 32));
More info:
Using the == operator to compare floating-point numbers is, generally, a bad idea. The problem arises from the fact that, typically, results of calculations have to be ‘fitted’ into floating-point representation, which does not always match the perceived reality of what result should be produced.
What you could do is use the "floor" function in GML, to round the number down (ignoring decimals), this will give you the integer part of the real number (as Joe Ellis said above).
Or, you could do something a bit clever:
Code:
#macro Epsilon 0.1 // TODO: Set this to a double whose hex representation is 0x1 on little-endian machine! (4.9406564584124654E-324)
if (abs(image_index - 9) < Epsilon) // "image_index == 9"
{
image_speed = 0;
show_message("Condition was true; image speed has been set to 0");
}
else
{
show_message("Condition was false; image speed not modified");
}
Epsilon is your tolerance value, a minimum difference before a pair of real numbers are considered to be equal.
I am still newish in GM, so I don't know how do you define complex number in GML... But, there you go.
Also, remember, the "string" function will round down the number to the nearest 2 decimals, so if you show_message such number, you will get stuff like "9.23" in your case because as explained above, a
double rounding error.
Hopefully you learned something new from me.