visible variable not working at times

S

SusiKette

Guest
I'm using the visible variable to make the player invisible if they die until they respawn, but the built in visible variable is not working in this specific occasion. It works just fine when I'm making the player blink when their iframes are running. Anyone know why this is not working in this particular situation?

Code:
if(p_alive == 1 && player_iframe == 0) {
    p_lives--;
    with(obj_player) {
        p_alive = 0;
        audio_play_sound(se_explosion_big,70,0);
        player_death_timer = 120;
        obj_player.visible = false;
        player_death_x = player_x;
        player_death_y = player_y;
    }
}
 
L

Lars Karlsson

Guest
Don't know if this will solve it. Try removing the 'obj_player.' part in the obj_player.visible line. Since you're already 'inside' that object.
 

jazzzar

Member
what @Lars Karlsson might be true, the with object already make you control the object player, and another thing you can try, in the draw event of the player, make an if statement to check for whatever you want, inside it put draw_self(), so the player gets drawn only if he's alive maybe
 
J

jackhigh24

Guest
it could also be an issue with the iframe as == will mean its has to be bang on 0 but it could be 0.100000 so floor it.
 
S

SusiKette

Guest
it could also be an issue with the iframe as == will mean its has to be bang on 0 but it could be 0.100000 so floor it.
Yes, could be, except that other stuff inside the if statement run as they should. The death timer runs as it is responsible for timing the randomly placed explosions near the death point and respawning once the timer runs out. The sound effect plays just fine too.

Don't know if this will solve it. Try removing the 'obj_player.' part in the obj_player.visible line. Since you're already 'inside' that object.
Didn't make a difference. I've also tried using image_alpha, but it works the same way as visible variable.

and another thing you can try, in the draw event of the player, make an if statement to check for whatever you want, inside it put draw_self(), so the player gets drawn only if he's alive maybe
Can you elaborate this one?
 
L

Lars Karlsson

Guest
Are you 100% sure that you are not setting the visible var to true somewhere else afterwards? That is the only thing I can think of atm.

EDIT: Just to clarify. All the other lines inside the with() statement is running and working?
 
J

jackhigh24

Guest
or if you are handling this in a draw event let say you have set in draw event that if visible == false then dont draw, then that would not work as the draw event wont run any code if you set it to visible = false.
 
S

SusiKette

Guest
Are you 100% sure that you are not setting the visible var to true somewhere else afterwards?
Yeah, I was setting it to true in the object's main code when iframes are 0, but since they were not set to non zero value on death it kept the player visible until the iframes were set on respawn making the player blink. I just added that the if statement checks if the player is alive or not before setting the player visible in that part of the code.

Thanks for pointing this out :)
 
Top