weapon: Weapon.js - Pastebin.com
bullet: Bullet.js - Pastebin.com
When my extraAmmo comes to 0 bullets, still i can reload five bullet to my current clip
and even with 4, or minus bullet in extraammo i can reload 5 bullets.
Well, you basically say if you have extraAmmo <=0, you can’t reload.
BUT later you ask “if currentClip < 5”, you CAN reload.
You should work on your switches.
I think this should do the work. I did not change it too much.
Try and see if there are any other ways to make it clearer and minimize code re-use.
function booleans()
{
if(extraAmmo <= 0)
{
extraAmmo = 0;
canReload = false;
}
else if(currentClip < 5)
{
canReload = true;
}
if(currentClip <= 0)
{
canShoot = false;
}
else
{
canShoot = true;
}
if(canShoot == true)
{
shootUp();
}
}
I think it’s much cleaner to caclulate the bools directly:
if(extraAmmo < 0)
extraAmmo = 0;
canReload = extraAmmo > 0 && currentClip < 5;
canShoot = currentClip > 0;
if(canShoot)
shootUp();
I agree, but I wanted to fix his code, not rewrite it.
I like reaching conclusions by myself, otherwise they don’t stick in.
I figure it’s the best way to help.
Thanks for every1, but I have 1 bullet in my extraAmmo with 1 bullet in my currentClip, for example. Still I can reload and receive 4 bullets, even with 1 extraAmmo
if(canReload == true){
if(Input.GetKeyDown(KeyCode.R)){
difference = extraAmmo - currentClip;
currentClip += difference;
extraAmmo -= difference;
}
You have always used “5” when calculating the difference, instead of the ammo you currently have (the above code is fixed).