#Reloading bug
1 messages · Page 1 of 1 (latest)
I would highly suggest you rename magazineSize to maxMagazine
I would highly suggest you rename magazineSize to maxMagazineSize
got it
use the renaming function to rename all instances of it
right click it and select rename
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
just transferring your code here for easier reference
sure
perhaps, you can try describing what each of the if statements are supposed to check?
the ones that allow you to reload
then you can catch maybe a logical error
gimme a sec
so these
if (Input.GetKeyDown(KeyCode.R) && currentMagazineSize < ammunition && !reloading && ammunition != 0)
{
Reload();
}
else if (Input.GetKeyDown(KeyCode.R) && currentMagazineSize > ammunition && !reloading && ammunition != 0)
{
Reload();
}
else if (readyToShoot && !reloading && currentMagazineSize == 0 && ammunition != 0)
{
Reload();
}
else if (Input.GetKeyDown(KeyCode.R) && ammunition == 0)
{
return;
}
1st one is where if the currentMagsize is lesser than ammunition and if is not reloading and ammunition is not 0
2nd is that else if is if the currentMagsize is greater than the ammunition and is not reloading and ammunition is not 0
3rd is where to fix the thing where I don't automatically reload if the currentMagsize hits 0
4th is I don't reload at all if there's no more ammo
okay can you tell me why for the 2nd one, you'd want to reload if the number of bullets in your magazine is more than the amount of ammo you have
oh so basically
max mag size is 15
ammunition is 30
after using it, it becomes
14/8
so yeah i want to reload the gun with that one bullet from the ammunition that is 8
why would you check if currentMagazineSize is more than your ammunition in order to reload?
maybe let's take a step back and try to get the basic logic down first?
I want to help because this is an interesting problem
it is indeed interesting, because i have made all the logics behind reloading a gun in my game right except this issue
so if I understand correctly, the intended behaviour for when to reload is
- if your currentMagazineSize is less than the maxMagazineSize
- if you're not already reloading
- if your ammunition is more than 0
is this correct? are there other situations I'm missing?
yeah you are right
if(!reloading && ammunition > 0 && currentMagazineSize < maxMagazineSize)
{
Reload();
}
does that look right to you?
if you're not reloading, and you have ammo in your reserves, and your magazine is not full, then reload
that sounds about right yeah
you can put that inside the Input.GetKeyDown(KeyCode.R)
so am i to replace that with the second else if?
you could technically replace the current reloading if else tree with this
if(Input.GetKeyDown(KeyCode.R))
{
if(!reloading && ammunition > 0 && currentMagazineSize < maxMagazineSize)
{
Reload();
}
}
i know there's still this
but technically, that can be solved by checking if your ammo is 0 after shooting
how're you feeling?
im actually feeling thankful
you know
being a student that took programming as a course and then just started at game development too is really challenging
but its fun
i did, but i still have to you know read em again to further understand it
sure, take care, ill notify you when something happens cheerios!
sure, even if it's to tell me it worked.
happy to help. see ya
@winged lintel im back
damn thank you
it works now
the reload system finally works
and for that
i thank you my friend
the problem was in my if logic statements
the conditions werent really correct
thanksss
yeah, that's what I figured, hence why I helped refactor it XD