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

GML [Solved] Rare Glitch - Gun Not Reloading

R

Red Phantom

Guest
So the gun successfully reloads 95% of the time, but on the rare occasion it does not re-load and the character cannot shoot to kill the enemies meaning he dies to the enemies and the game restarts.

Code:
Keyboard Event for Z-key Key(i.e. when the main character presses z, shoot!):

execute code:

///SHOOT
if global.inconversation = true or instance_exists(obj_Red_Building_Locked_Text_Orphan) exit;

if loaded = true and sprite_index != spr_Meskhenet_Walking and vsp = 0
  {
  separate_bullets = instance_create(x + 10,y + 18,obj_Bullet); //relative origin of bullets has been tested and is correct.
  if image_xscale = 1
    {
    separate_bullets.hspeed = 10
    sprite_index = spr_Meskhenet_Walking_with_Pistol_Shot_Flipped
    pistol_recoil_count = 1
    }
  if image_xscale = -1
    {
    separate_bullets.hspeed = -10
    separate_bullets.x -= 25 //when Meskhenet faces other direction bullets x_origin must be adusted appropriately
    sprite_index = spr_Meskhenet_Walking_with_Pistol_Shot
    pistol_recoil_count = 1
    }
 
  loaded = false
  script_execute(scr_Set_Time_Line,tml_Re_Load,false)
  }
 
if loaded = true and sprite_index != spr_Meskhenet_Jumping and vsp !=0
  {
  separate_bullets = instance_create(x + 10,y + 18,obj_Bullet_Jumped); //relative origin of bullets has been tested and is correct.
  if image_xscale = 1
    {
    separate_bullets.hspeed = 7.07
    separate_bullets.vspeed = 7.07
    sprite_index = spr_Meskhenet_Jumping_with_Pistol_Shot_Flipped
    pistol_recoil_count = 1
    }
  if image_xscale = -1
    {
    separate_bullets.hspeed = -7.07
    separate_bullets.vspeed = 7.07
    sprite_index = spr_Meskhenet_Jumping_with_Pistol_Shot
    separate_bullets.image_xscale = -1
    separate_bullets.x -= 20 //when Meskhenet faces other direction bullets x_origin must be adusted appropriately
    pistol_recoil_count = 1
    }
 
  loaded = false
  script_execute(scr_Set_Time_Line,tml_Re_Load,false)
  }
The timeline used to re-load the gun!
Code:
Information about time line: tml_Re_Load


Step   15:
execute code:

loaded = true
The enemy(obj_soldier) also shoots and uses tml_Re_Load!
Code:
Step Event:

execute code:

///SHOOT
if obj_Meskhenet.meskhenet_health = 0 then exit
if global.inconversation = true then exit
//The next two lines fix Bug 39
if instance_number(obj_Exit_Game) = 1 then exit
if instance_number(obj_Red_Building_Locked_Text_Orphan) = 1 then exit

if obj_Meskhenet.vsp != 0 then exit

if loaded = true
  {
  if obj_Meskhenet.x > x + 20 //If Meskhenet is right of soldier (was 38)
    {
    instance_create(x + 26,y + 22,obj_Enemy_Bullet); //Shoot Right
    (obj_Enemy_Bullet).hspeed = 10;
    pistol_recoil_count = 1
    }
  if obj_Meskhenet.x < x + 1 //If Meskhenet is left of soldier
    {
    instance_create(x - 3,y + 21,obj_Enemy_Bullet); //Shoot Left
    (obj_Enemy_Bullet).hspeed = -10;
    pistol_recoil_count = 1
    }
  loaded = false
  script_execute(scr_Set_Time_Line,tml_Re_Load,false)
  }
 
//Pistol Recoil Count
if pistol_recoil_count > 0 then pistol_recoil_count += 1

finished_recoil_timer = 6
if pistol_recoil_count = finished_recoil_timer
  {
  sprite_index = spr_Soldier_Walking_Pointing_Gun
  }
 
R

Red Phantom

Guest
Like this?
tml_reload.PNG
I tried this it does not do anything when the re-load error occurs, perhaps because step 15 of the timeline is not being reached or the timeline is not at all being run.
 
R

Red Phantom

Guest
I just inputted the code as suggested. When the error occurred, the debug message did not show, so the timeline is not running? How do I fix this?
 

Vishnya

Member
I just inputted the code as suggested. When the error occurred, the debug message did not show, so the timeline is not running? How do I fix this?
May be problem in script. Or in variables in if statements. You should enable debug mode and see where you were wrong
 
Top