GMS 2 An odd result... possible bug? [SOLVED]

PlayerOne

Member
I don't know what to make of this. I'm trying to implement a weapon switching system. The problem comes when I switch weapons and I have seem to have pinpointed the issue to instance_create_depth.

What should happen is that when I pick up a new weapon the previous one gets dropped with the remaining ammo it had. In theory anyway.

In reality, when I switch to a new weapon from the weapon I just picked up I get transported to different room. This shouldn't happen at all. No code says that I should be going to another room. Yet this happens anyway.

I messed with it for a while and the results are always the same no matter what I do. I disabled the instance_create_depth function in another test and I don't get this room transport bug at all.

Any ideas?

Just to clarify ammo_1, ammo_2, weapon_1, weapon_2 are macro's that connect to the same ds_grid.

Code:
if place_meeting(x,y,oPlayer) && keyboard_check_pressed(vk_e)
{
   
   switch (current_weapon)
   {
   case 0:   
       
       if (weapon_1==weapon_id.Empty || weapon_1==weapon_type)
       {
       
               if ammo_remaining!=-1
               {
               ammo_1+=ammo_remaining; // <<< Add amount to NEW current weapon
               }
               else
               {
               ammo_1+=ammo_amount; // <<< Add ammo
               weapon_1=weapon_type; // <<< Add weapon id to weapon_2
               }
       

       }
       else if weapon_1!=weapon_id.Empty || weapon_1!=weapon_type // <<< If a weapon is found
       {
       
           var weapon = instance_create_depth(x+0,y+0,-25,global.loot[# weapon_1,2]) // <<< Create "dropped" weapon
           with (weapon)
           {
           ammo_remaining=ammo_1;
           }
       
               if ammo_remaining!=-1
               {
               ammo_1=ammo_remaining; // <<< Add amount to NEW current weapon
               }
               else
               {
               ammo_1=ammo_amount;   
               }
                   
               weapon_1=weapon_type // <<< // <<< Add weapon id to weapon_2
   
       }
   
   break;
   
   case 1:   
       
   if (weapon_2==weapon_id.Empty || weapon_2==weapon_type)
   {
       
           if ammo_remaining!=-1
           {
           ammo_2+=ammo_remaining; // <<< Add amount to NEW current weapon
           }
           else
           {
           ammo_2+=ammo_amount; // <<< Add ammo
           weapon_2=weapon_type; // <<< Add weapon id to weapon_2
           }
       
       }
       else if weapon_2!=weapon_id.Empty || weapon_2!=weapon_type // <<< If a weapon is found
       {
       
           var weapon = instance_create_depth(x+0,y+0,-25,global.loot[# weapon_2,2]) // <<< Create "dropped" weapon
           with (weapon)
           {
           ammo_remaining=ammo_2;
           }
       
               if ammo_remaining!=-1
               {
               ammo_2=ammo_remaining; // <<< Add amount to NEW current weapon
               }
               else
               {
               ammo_2=ammo_amount;   
               }
                   
               weapon_2=weapon_type // <<< // <<< Add weapon id to weapon_2
   
       }
   
   break;
   
   }
   
   instance_destroy();   // <<< Destroy instance
   
}
 

Simon Gust

Member
keyboard_check_pressed(vk_e)

maybe somewhere in your project you have code that reacts to this input and changes rooms.
 

PlayerOne

Member
keyboard_check_pressed(vk_e)

maybe somewhere in your project you have code that reacts to this input and changes rooms.
That's a macro. Short for ord("E"). Saves alot of time while programing.

After more tests I realized that my first object in the resource tree is connected to room_next function causing this problem. I forget that you can feed instance_create with a number instead of a name. After giving myself a headache yesterday this was the cause.

Lesson learned I guess.
 
Last edited:
Top