Legacy GM Background disappears for no reason.



So i've been playing around with scripts for a while and i encountered a weird bug just now. Sometimes when the player object is hit, the background may sometimes disappear.

A gif with what is happening is below:

I have no idea why this is happening, since those things are not related in any way..
The script is as follows:

var inst = instance_place(x, y, obj_player);

with(inst) {
    obj_player.damage = atk;
    if type = 2 {

var atk_value = (damage - def);

if atk_value < 1 {
    atk_value = 1;

hp -= atk_value;
iframes = 25;

xspd = (xspd / -xspd) * 3.5;
yspd = -5;

And the background is set in the room options..

Also i did this simple thing with invulnerability frames, if it can mean anything:

if iframes = 0 || (iframes mod 5) < 3 {

There is no reference to the background ANYWHERE in the game.
If anyone knows, why this may happen, please let me know.


Update: background disappears when this line of code is in use, and when player's "xspd" (horizontal speed) is 0:
xspd = (xspd / -xspd) * 3.5
Any ideas on why that is a thing?

Edit: I'm an idiot. It's trying to divide by 0, so that's the problem, is it?


dividing by 0 is always a problem however I'm not sure how that's the problem?
Usually when dividing by 0 you get an error that yells at you for trying such nonsense, not only that but why would it affect the background??
maybe your computer is just weird

Anyway this is a hit script, what exactly were you trying to do with (xspd / -xspd)?
if you really were just trying to get the direction you're moving then, as Cat said, use sign.
But it looks like you were trying to make the player jump away from where they got hit from? If so you should save the direction from which you were hit:
sign(player.x - enemy.x)
then set your xspd based on that direction:
xspd = 3.5 * that_direction;


TMC Founder
GMC Elder
you don't get an error when you divide by 0 now, you get infinity (in js), or the maximum possible value a double can hold and I'm pretty sure GML does that now


Anyway guys, so i have this fixed now, it's not a big problem anymore.

What i tried to do with this, was a knockback mechanic, like in Castlevania or something. So i tried to reverse the value and make it a set number.
I'm just stupid though and can't think of a simple way to do stuff, so i often overcomplicate things..