Code just stopped working

Okay so this code was working fine before. I have an object that set's it prevous hp to it's hp on the end step event then check it on the step event for change, if there is change it checks if it's below 0 then destroys it. However this doesn't work anymore i havn't edited the code it has just stopped working:

End Step event:
Code:
prev_hp = hp;
Step Event:
Code:
if prev_hp > hp
{
    if player.can_hit = true
    {
        create_particle(x,y,3,3,pcol1,irandom_range(2,4));
        create_particle(x,y,3,3,pcol2,irandom_range(2,4));
        play_rand_sound(snd_hit,10,0.1);
    }
    if hp <= 0
    {
        instance_destroy();
    }
}
This was being done by a parent object but i do have the call inherited event on there
So i moved it into the object but still doesn't work
I returned its hp variable and it is in fact going down as it should be but the code which was working fine no longer works. (The only thing i can remember doing is moving it's parent event into a group)

From what i can tell the code has just decided to stop working.

EDIT: The step event is working but for some reason the prev_hp isn't being set properly (This has been working fine for 6 days until now.)
 
Last edited:
are you sure there is something affecting the variable hp between those codes? it might be a problem that you check if hp_prev < hp before the hp changes
 
are you sure there is something affecting the variable hp between those codes? it might be a problem that you check if hp_prev < hp before the hp changes
I havnt touched any of the items that use the code and scripts related to breaking objects and stuff, it's the player object that lowers the hp of this object and neither of them have been touched, they just don't work anymore. It was working fine 2-3 hours ago, all i have done since then is moved the objects into groups, added clouds erm and that's it
 
are you sure there is something affecting the variable hp between those codes? it might be a problem that you check if hp_prev < hp before the hp changes
NO WAY!, okay it was the moving them into groups that was the problem, i moved the player back to the top of the objects list (on the left side of the screen) and boom it works again. I didn't realise the objects list had any importance in the game whatsoever apparently it does.
 
thats really strange. The only way I can think of then is either the code isent executed or the hp_prev variable gets changed somewhere else.
 
thats really strange. The only way I can think of then is either the code isent executed or the hp_prev variable gets changed somewhere else.
Thanks for the help figured it out now (The comment above), you gave me the thought to move the player back to the top of the objects list instead of under the groups(folders) i had just created. That seems to make a difference
 
I could have sworn that the order in the IDE doesn't matter but I guess it does, thanks for letting me know!
Yeah i thought the same thing, i think it's because they all have the same depth so it uses the IDE to work it out, bit silly if you ask me, really it should be whatever object is created first i think (Just to get consistent results)
 

Smiechu

Member
I've experienced the same thing couple of days ago, and asked here if somebody knows of any changes.
Anyway, how the hell should position in resource tree have any influence to code execution? This is the most stupid thing...
 
M

Menik

Guest
I've been going through some strange errors myself. Specifically a collision event. Just like the title my code had just stopped working, and a specific instance was no longer colliding with what it was supposed to--without me touching any code.

------------------------

So apparently, the most recent update changed how collision works or maybe it's another bug, but it does have to do with the order of the instances. I don't know if that speaks to this situation at all, but it would seem that it does.
 

MIchael PS

Member
Okay so this code was working fine before. I have an object that set's it prevous hp to it's hp on the end step event then check it on the step event for change, if there is change it checks if it's below 0 then destroys it. However this doesn't work anymore i havn't edited the code it has just stopped working:

End Step event:
Code:
prev_hp = hp;
Step Event:
Code:
if prev_hp > hp
{
    if player.can_hit = true
    {
        create_particle(x,y,3,3,pcol1,irandom_range(2,4));
        create_particle(x,y,3,3,pcol2,irandom_range(2,4));
        play_rand_sound(snd_hit,10,0.1);
    }
    if hp <= 0
    {
        instance_destroy();
    }
}
This was being done by a parent object but i do have the call inherited event on there
So i moved it into the object but still doesn't work
I returned its hp variable and it is in fact going down as it should be but the code which was working fine no longer works. (The only thing i can remember doing is moving it's parent event into a group)

From what i can tell the code has just decided to stop working.

EDIT: The step event is working but for some reason the prev_hp isn't being set properly (This has been working fine for 6 days until now.)

I don't know if you are using such a complex system for a specific reason, but you don't need all those variables to check the hp and if it's equal to zero, destroy the instance.
If that helps, you can just say (in the step event) :

Code:
if hp <= 0
{
    instance_destroy();
}
I hope this helped...
 

MIchael PS

Member
Well actually as I can see you are using this method to check if the object is hit. You can do it by adding either a colision (with a hitbox) or a variable setting/resetting when hit. Maybe this helps...
 
Top