• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Change sprite when walking through obj and then back

G

General Woodchuck

Guest
I'm having trouble getting this sprite to start and stop when it should. I was wondering if anyone could help?

Basically I've got a window object that, if it's open and I try to walk through it, he jumps through it. The Alarm[0] code resets 'timer' to 0 and sets the trig_jump% vars to false.

But when my guy jumps through he usually does it late, if at all, and then he gets stuck on the sprite_index, almost as if the alarm[0] isn't triggering, but I put a message box in it to test it and it worked, but for some reason my player is still staying stuck in the winJumpS sprite.

EDIT: The alarm isn't triggering when it should. Somehow it triggers before the "North" or "South" message boxes below trigger. I don't understand how that's possible. When it gets stuck I hit Alt to show the debugging I added below and it says that timer=1 & the trigger=true, but I can't figure out why the alarm isn't going off when it should.

Does anyone know of an example of something like this I could reference? I feel like I'm over thinking this.


Code:
{//movement through open windows
    {//window is North of player
   
    if (keyboard_check_pressed(vk_alt))
        {
        show_message
            (
            "trig_jumpN="+string(trig_jumpN)+"#"+
            "trig_jumpS="+string(trig_jumpS)+"#"+
            "timer="+string(timer)+"#"+
            "bbox_top="+string(bbox_top)+"#"+
            "winX.bbox_top="+string(winX.bbox_top)+"#"+
            "bbox_bottom="+string(bbox_bottom)+"#"+
            "winX.bbox_bottom="+string(winX.bbox_bottom)
            )
        }
   
        if(winX.isOpen==true&&vspeed<0&&(bbox_top>=winX.bbox_bottom)&&timer==0)//If window is to the North
            {
            show_message("North")
            trig_jumpN=true;
            timer=1;
            }
        if(trig_jumpN==true&&timer==1)
            {//do stuff
            alarm[0]=room_speed*.6;
            x+=winX.x-x;
            y+=winX.bbox_top - bbox_bottom-3;
            sprite_index=winJumpS;
            }
        //window is South of player
        if(winX.isOpen==true&&vspeed>0&&(bbox_bottom<=winX.bbox_bottom)&&timer==0)//If window is to the South
            {
            show_message("South")
            trig_jumpS=true;
            timer=1;
            }
        if(trig_jumpS==true&&timer==1)
            {//do stuff
            alarm[0]=room_speed*.6; 
            x+=winX.x-x;
            y+=winX.bbox_bottom - bbox_top+3;
            sprite_index=winJumpS;  //change to winJumpN once you draw the dang thing     
            }
    }
}
 
Last edited by a moderator:

Relic

Member
The conditions that result in alarm[0]=0.6*room_speed being run are still true in future steps. Once you detect it’s jumping through a window time, the alarm will never reach 0 because you keep resetting it.
 
Top