Instance_create_layer facing

F

FoxandRavenGames

Guest
I have a locked chest and when i interact with it while i have a key it spawns the unlocked chest. When i set my Locked chest i either set it there or mark "Flip X" on the object in room. I want my unlocked chest to spawn the same direction as locked chest. thanks for the help. The code below is my collision code on o_player with o_chest_locked.
GML:
if keys >= 1 {
with(other) {
        can_pickup = true; {
        die = true;
        with(other) {
             if keys > 0 {
                 keys--;
                 var inst = instance_create_layer(o_chest_locked.x, o_chest_locked.y, "Chest", o_chest_unlocked);
                 with(inst)
                 {
                    effect_create_above(ef_smoke, o_chest_locked.x, o_chest_locked.y + 9, .08, c_purple);
                 }
        }
        audio_play_sound(snd_unlock_chest, 15, false);
        }
    }  
}
}
 

TheouAegis

Member
In the same place you are creating the smoke effect, set whatever variables you need to to make the chest face the right direction.
 
F

FoxandRavenGames

Guest
In the same place you are creating the smoke effect, set whatever variables you need to to make the chest face the right direction.
i tried to do "direction = other.facing" and create a variable for facing.. tried "direction = o_chest_unlocked.image_xscale" and a few other things. im not sure if it isn't reading it because it was already destroyed. I can go in to each object in room and do creation code to make them face correctly but was hoping to avoid having to do that with each chest
 

NightFrost

Member
You have three nested with() functions there, so when you invoke source of data using other inside there, make sure the other is actually what you wanted to refer to. Actually I'm unsure what happens when you invoke nesting with(other) twice, does it ping-pong between the ID values, or does it always reference the same target (thus making the second call unnecessary). However you should be able to figure what current scope is by debug messaging id.
 
F

FoxandRavenGames

Guest
So you know that image_xscale tells you which way the sprite is flipped, but you're setting direction (direction of movement)... why?
oh ha youre right that was stupid. i actually figured it out, i created a whole new variable and set it as spawning to the facing direction of the the object that was destroyed
 

TheouAegis

Member
You have three nested with() functions there, so when you invoke source of data using other inside there, make sure the other is actually what you wanted to refer to. Actually I'm unsure what happens when you invoke nesting with(other) twice, does it ping-pong between the ID values, or does it always reference the same target (thus making the second call unnecessary). However you should be able to figure what current scope is by debug messaging id.
It ping-pongs. It should just be a stack push-pop. The first with pushes A's (caller's) id to the stack. The with(other) pops from A from the stack, saves it to a register/variable, pushes B to the stack. Thus the next with(other) pops B, saves it, pushes A.

You can even stack others, or used to.

with instance_create(irandom(room_width), irandom(room_height), obj_ball) {
with instance_create(x,y,obj_googlyeyes) {
image_angle = other.other.image_angle);
}
}

That would be a pop-pop-reverse push-push-push, I think. Like you said, debugging would clear that up.
 

NightFrost

Member
Well, makes sense that it is a stack. Technically this means OP also could, instead of calling with(other) twice, just close the first one to return to original scope. Less code, less mental gymnastics to figure actual scope.
 
Top