• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Problem with ammunition code

H

HieNa

Guest
I have problem with my code i have a Create code:
ammo = 0;
weapon[1,1] = 20 // This is an ammuniction what i have in my Player object,
In STEP Event i make a code:
ammo = weapon[weaph,1]; // weaph is weapon actualy choosed

now i want to check work code, i make Event Global Mouse Left down ammo -= 1; but nothing this is not work, ammo still is on 20, when i make a step Event code:
if mouse_check_button(mb_left){
if weaponh > 0{
if ammo > 0 {
ammo -= 1;
}
}
}
When i click LMB and hold it, my ammo is on 19, but when in relase LMB value going to 20. Can u help me what i do wrong?


CREATE:

// SECONDARY //

weapon[1,0] = true; // Have Weapon
weapon[1,1] = 20; // Ammo
weapon[1,2] = 20; // Max Ammo
weapon[1,3] = 2; // Mag
weapon[1,4] = 3; // Max Mag
weapon[1,5] = 1; // Reload Time
weapon[1,6] = 1; // Shot Time
weapon[1,7] = 5; // DMG
weapon[1,8] = 15; // MAX DMG
weapon[1,9] = 3; // Armor Penetration
weapon[1,10] = "Test1"; // Name

STEP:

ammo = weapon[weaponh,1];
maxammo = weapon[weaponh,2];
mag = weapon[weaponh,3];
maxmag = weapon[weaponh,4];
reloadtime = weapon[weaponh,5];
shottime = weapon[weaponh,6];
dmg = weapon[weaponh,7];
maxdmg = weapon[weaponh,8];
armorp = weapon[weaponh,9];
weapname = weapon[weaponh,10];
 

FrostyCat

Redemption Seeker
When you do this:
Code:
ammo = weapon[weaph,1];
You are NOT binding ammo to weapon[weaph, 1], you are simply copying the value of weapon[weaph, 1] at that point in time into ammo. Running ammo -= 1; later in the Step will not automatically decrement weapon[weaph, 1]. Right now you are just resetting ammo back to the same value every step.

If your intention is to keep the running totals updated, add weapon[weaph, 1] = ammo; at the end of the Step event so that changes to ammo during the Step event are reflected back in the original array.
 

Simon Gust

Member
What happens is that ammo is being set to 20 every step by this code
Code:
ammo = weapon[weaponh,1];
and if you press the mouse button it is being subtracted by 1 by this code...
Code:
if mouse_check_button(mb_left){
  if weaponh > 0{
    if ammo > 0 {
      ammo -= 1; 
    }
  }
}
...setting it to 19 at the end of that step.
 
H

HieNa

Guest
When you do this:
Code:
ammo = weapon[weaph,1];
You are NOT binding ammo to weapon[weaph, 1], you are simply copying the value of weapon[weaph, 1] at that point in time into ammo. Running ammo -= 1; later in the Step will not automatically decrement weapon[weaph, 1]. Right now you are just resetting ammo back to the same value every step.

If your intention is to keep the running totals updated, add weapon[weaph, 1] = ammo; at the end of the Step event so that changes to ammo during the Step event are reflected back in the original array.
Thanks, that's work.
 
Top