• 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!

GameMaker 90.00 != 90? strange integer interaction

T

Toomuchbob

Guest
Code:
/// @description Player is moving

//clamp x
if (x == clamp(x, target_x - 0.5, target_x)) {
    x = floor(target_x);
} else {
    show_debug_message(target_x);
    x = lerp(x, target_x, .125);
}

//clamp y
if (y == clamp(y, target_y - 0.5, target_y)) {
    y = floor(target_y);
} else {
    show_debug_message(target_y);
    y = lerp(y, target_y, .125);
}

//clamp direction
if (dir < target_dir) {
    if (dir == clamp(dir, target_dir - 1, target_dir)) {
        dir = floor(target_dir);
    } else {
        show_debug_message(target_dir);
        dir = lerp(dir, target_dir, .125);
    }
} else {
    if (dir == clamp(dir, target_dir, target_dir + 1)) {
        dir = floor(target_dir);
    } else {
        show_debug_message(target_dir);
        dir = lerp(dir, target_dir, .125);
    }
}

//set player state
if (x == target_x and y == target_y and dir == target_dir) {
    _playerController.state = playerIdle;
} else {
    _playerController.state = playerMoving;
}
This code when testing won't set my state variable to playerIdle, even though the varibles are equal. Only thing I can figure through testing is that they get set to the nearest hundredth, and game maker thinks they aren't equal. I know the above code is kind of a mess it's just what I'm left with now after hours of troubleshooting.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
http://docs2.yoyogames.com/index.ht...erence/maths/real valued functions/index.html

but due to the way that floating point maths works, it may mean that image_index actually equals 1.00000000001, in which case the comparison will never result in a true result and the code running. These types of errors can be quite hard to debug and so it is always good to be aware of them and to plan ahead and use other means of checking values or to use the appropriate flooring or rounding functions (listed below) to convert the number to check into an integer.
;)
 

TheouAegis

Member
Where else are you affecting x and y? A .125 keep (1/8) shouldn't cause fp errors like that unless x or y wasn't an integer to begin with.
 
J

JFitch

Guest
I've had this problem when using logarithms. Before testing whether a variable equals something, use this code:

Code:
n = round(1000*n)/1000
This code will round n to the nearest 1000th. You can change n to a different variable or change the number 1000 to round to a different place value.
 

Mike

nobody important
GMC Elder
personally... I never use round, I always use floor. it gives much more predictable results.
 
Top