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

Doors

W

Wild_West

Guest
Alright so I've tried everything can think of for this and it'as not working.

What I'm trying to do is make a setup of pairs of doors. so I can walk up to one, press up and go to the second door of the pair. But every time I set it up it only works when going back from door 2 to door 1, and door 1 just keeps setting me at door 1. UNLESS I only have code to travel from one door, then door 1 does work. what is the deal ?


Code:
if( gamepad_button_check_released( 0, gp_padu ) )
{
   with( other )
   {       
       switch( instance_number( door_obj ) )
       {
          case 2 :
         
          if( place_meeting( x, y, other ) )
          {
             var door_2 = instance_find( door_obj, 1 );
             x = door_2.x;  y = door_2.bbox_bottom;
          }

          if( place_meeting( x, y, other ) )
          {
             var door_1 = instance_find( door_obj, 0 );
             x = door_1.x;  y = door_1.bbox_bottom;
          }
       }
   }
}
 
Why are you using a switch like that? Are there more than two doors (or plans for more than two) in the room or literally just two? What event is this in? A collision event? I'll assume it's in a collision event with the door and the object that is running the code is the player object.

The below code should work if all of these criteria are met: The code is in the player object. The event it's placed in is the collision event. There is literally only ever two doors in the room.
Code:
if (gamepad_button_check_released(0,gp_padu)) {
   var player_id = id;
   with (other) {
      var current_id = id;
      with (door_obj) {
         if (current_id != id) {
            player_id.x = x;
         }
      }
   }
}
 
W

Wild_West

Guest
Why are you using a switch like that? Are there more than two doors (or plans for more than two) in the room or literally just two? What event is this in? A collision event? I'll assume it's in a collision event with the door and the object that is running the code is the player object.

The below code should work if all of these criteria are met: The code is in the player object. The event it's placed in is the collision event. There is literally only ever two doors in the room.
Code:
if (gamepad_button_check_released(0,gp_padu)) {
   var player_id = id;
   with (other) {
      var current_id = id;
      with (door_obj) {
         if (current_id != id) {
            player_id.x = x;
         }
      }
   }
}
yes I was planning on having more than just the two this is just testing to make sure it at least works with the minimum number. It's the door running the code for a collision with the player.
 

chamaeleon

Member
Alright so I've tried everything can think of for this and it'as not working.

What I'm trying to do is make a setup of pairs of doors. so I can walk up to one, press up and go to the second door of the pair. But every time I set it up it only works when going back from door 2 to door 1, and door 1 just keeps setting me at door 1. UNLESS I only have code to travel from one door, then door 1 does work. what is the deal ?


Code:
if( gamepad_button_check_released( 0, gp_padu ) )
{
   with( other )
   {      
       switch( instance_number( door_obj ) )
       {
          case 2 :
        
          if( place_meeting( x, y, other ) )
          {
             var door_2 = instance_find( door_obj, 1 );
             x = door_2.x;  y = door_2.bbox_bottom;
          }

          if( place_meeting( x, y, other ) )
          {
             var door_1 = instance_find( door_obj, 0 );
             x = door_1.x;  y = door_1.bbox_bottom;
          }
       }
   }
}
I'm not going to try to reason out logically what goes wrong, but as a start, can you explain your reasoning behind having two if statements without an else, where the second if statement depends on potentially changed x/y variables from the first if statement?
 
W

Wild_West

Guest
I'm not going to try to reason out logically what goes wrong, but as a start, can you explain your reasoning behind having two if statements without an else, where the second if statement depends on potentially changed x/y variables from the first if statement?
I tried the code with an else , made no difference
 

TheouAegis

Member
If you're going to have multiple doors, what you should be doing is and each doors creation code, assign it a Target door to move to. then even if you had 50 diors in your room, your code would only be three or four lines long.
 
W

Wild_West

Guest
If you're going to have multiple doors, what you should be doing is and each doors creation code, assign it a Target door to move to. then even if you had 50 diors in your room, your code would only be three or four lines long.
creation code didn't work either.

I tried setting an id variable, door_1, door_2, if colliding with this door and it's id = door_1 move to door_2's x and y. and vice versa. Every time I change it it only works going one way
 

chamaeleon

Member
creation code didn't work either.

I tried setting an id variable, door_1, door_2, if colliding with this door and it's id = door_1 move to door_2's x and y. and vice versa. Every time I change it it only works going one way
When you say creation code you do mean setting the id of the opposing door in the instance create code in the room editor for both instances, not in the object create code, right? And I will also assume that step or collision code does not look anything much like your opening post code so you should post that too.
 
Top