Code just stopped working

Discussion in 'Programming' started by FeetUpGaming, Jun 10, 2018.

  1. FeetUpGaming

    FeetUpGaming Member

    Joined:
    Apr 2, 2017
    Posts:
    104
    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: Jun 10, 2018
  2. Carl Nylander

    Carl Nylander Member

    Joined:
    Jul 21, 2016
    Posts:
    212
    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
     
  3. FeetUpGaming

    FeetUpGaming Member

    Joined:
    Apr 2, 2017
    Posts:
    104
    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
     
  4. FeetUpGaming

    FeetUpGaming Member

    Joined:
    Apr 2, 2017
    Posts:
    104
    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.
     
    Carl Nylander likes this.
  5. Carl Nylander

    Carl Nylander Member

    Joined:
    Jul 21, 2016
    Posts:
    212
    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.
     
  6. FeetUpGaming

    FeetUpGaming Member

    Joined:
    Apr 2, 2017
    Posts:
    104
    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
     
  7. Carl Nylander

    Carl Nylander Member

    Joined:
    Jul 21, 2016
    Posts:
    212
    I could have sworn that the order in the IDE doesn't matter but I guess it does, thanks for letting me know!
     
    FeetUpGaming likes this.
  8. FeetUpGaming

    FeetUpGaming Member

    Joined:
    Apr 2, 2017
    Posts:
    104
    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)
     
    Carl Nylander likes this.
  9. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    626
    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...
     
  10. Menik

    Menik Member

    Joined:
    Feb 19, 2018
    Posts:
    16
    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.
     
  11. MIchael PS

    MIchael PS Member

    Joined:
    Aug 12, 2017
    Posts:
    95

    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...
     
  12. MIchael PS

    MIchael PS Member

    Joined:
    Aug 12, 2017
    Posts:
    95
    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...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice