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

Variable set in Variable Definitions, but now null?

S

samspot

Guest
I have some code that used to work fine, but is now breaking so I'm not sure what relevant info to include.

It's happening only when i defeat the last boss of my game and transition to the ending room. This is based on Shaun Spaulding's series. The only other thing I can think of it started happening around the time I added different weapons for each character. It does not seem to break consistently, making me think there is a race condition. Any ideas?

upload_2020-1-17_14-9-35.png

upload_2020-1-17_14-11-57.png
 
A

Adjud

Guest
to me there error reads that your asking if "hp" is smaller than 0 before setting your enemies hp. check if the enemies variable "hp" is being set before the begin step event.
 
S

samspot

Guest
I am trying to show in the screenshot that it is, it's part of variable definitions. How can it be not set at the time of the step event? Also this is an enemy that was walking around, so it had many step events prior to the failure.
 
R

robproctor83

Guest
Your saying that this error occurs when you do a room transition, so what that means is that you are deleting the enemy and then trying to step through it. My assumption is that you have some other code in another object somewhere, somehow, that is going into the enemy and possibly running the event. You can, for example, from the player object execute the enemy step event. Can you think of anything in your code that might do such a think? I could be wrong, but that is my guess.

Another thought, try taking HP out of the definitions and just put it in the create event for a moment to see if that error still occurs. I don't use variable definitions so I am not too familiar with them, but I would assume it's no dif than adding them in the create.
 
C

Catastrophe

Guest
So basically, the clue here is that it's not saying "enemyName.hp" it's saying "unknown_object.hp". If you make an object called "derp" and run "stuff = lol" in a step event, you will get an error saying "derp.lol" isn't set.

In other words, the issue is not the variable but the object is running code it shouldn't. Probably caused by a destroyed object running code after being destroyed (which makes sense regarding your statement that it happens after the boss is destroyed)

Honestly, not sure exactly how that's happening, but hope that helps lol. I believe instance_destroy() will cause an object to continue running it's current event code which would cause issues, but I mean... that's the top of the event. Hopefully someone else can figure it out from here.

On a random hunch you can maybe hack fix this by running the destroy object code somewhere in the object itself and exiting, or (more likely) delaying the room transition a frame (perhaps by handling the transition in the controller, checking if the boss exists or not). But I'm curious how that's even happening. Where is instance_destroy() being called anyways? Room transitions have some weird ordering to events and are a source of mysterious bugs sometimes. Calling an immediate transition from a destroy event isn't something I'd risk given their nature. Either way, taking out the room transition and testing a few times will narrow down the issue.

In any case, you might get more accurate help by retitling as "[unsolved] unknown_object on room transition", since that's the problem at this point, not variable definitions (and I like rob, don't use them, haha, I think a lot of people don't know how they work)
 
Last edited by a moderator:
S

samspot

Guest
Hmm, that might help. I think i need to do some deep tinkering... the instance_destroy() is lower down in that step code! In my mind I can't comprehend how another step could ever be run. The screenshot shows the colission code, and it doesn't destroy - just sets hp to 0.

Thanks for your insights, Catastrophe and rbproctor83.

upload_2020-1-17_16-22-11.png

oenemy begin step

Code:
/// @description death code
if(hp <= 0){
    
    with(instance_create_layer(x, y, "Enemy", oDead)){
        sprite_index = other.mysprite
        
        direction = other.hitfrom   
        hsp = lengthdir_x(3, direction)
        vsp = lengthdir_y(3, direction)-5
        if(sign(hsp) != 0){
            image_xscale = sign(hsp) * other.size
            image_yscale = other.size
        }
        
    }
    
    if(instance_exists(oPlayer)){
        global.kills++
        global.killsthisroom++
        with(oGame) killtextscale = 2
    }
    
    with(mygun) instance_destroy()
    instance_destroy()
}
 
S

samspot

Guest
Is there an if(this_exists()){ } I can wrap around the whole thing to protect the check? Or can I catch the exception and ignore it?
 
S

samspot

Guest
It seems to be fixed by adding 'exit' after instance_destroy(). but instance_destroy() was already the last line of the event so this makes no sense to me. I also need further testing to see if its truly gone. I'm a noob in GML so i very well could be doing something weird.
 
C

Catastrophe

Guest
Yeah it's confusing. Also I would change:


with(mygun) instance_destroy()
instance_destroy()
->

with(mygun) {instance_destroy();}
instance_destroy()

Probably not the source of the issue, but it's probably not a good habit.
 
Top