#Reloading bug

1 messages · Page 1 of 1 (latest)

winged lintel
#

I would highly suggest you rename magazineSize to maxMagazine

#

I would highly suggest you rename magazineSize to maxMagazineSize

fiery sail
#

got it

winged lintel
#

use the renaming function to rename all instances of it

#

right click it and select rename

#

just transferring your code here for easier reference

fiery sail
#

sure

winged lintel
#

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

fiery sail
#

gimme a sec

winged lintel
#

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;
        }
fiery sail
#

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

winged lintel
#

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

fiery sail
#

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

winged lintel
#

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

fiery sail
#

it is indeed interesting, because i have made all the logics behind reloading a gun in my game right except this issue

winged lintel
#

so if I understand correctly, the intended behaviour for when to reload is

  1. if your currentMagazineSize is less than the maxMagazineSize
  2. if you're not already reloading
  3. if your ammunition is more than 0
#

is this correct? are there other situations I'm missing?

fiery sail
#

there's a fourth

#

one

#

but its doesn't matter

winged lintel
#

okay

#

so, technically you can simplify the logic into this

winged lintel
#
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

fiery sail
#

that sounds about right yeah

winged lintel
#

you can put that inside the Input.GetKeyDown(KeyCode.R)

fiery sail
winged lintel
#

you could technically replace the current reloading if else tree with this

if(Input.GetKeyDown(KeyCode.R))
{
  if(!reloading && ammunition > 0 && currentMagazineSize < maxMagazineSize)
  {
    Reload();
  }
}
winged lintel
#

but technically, that can be solved by checking if your ammo is 0 after shooting

fiery sail
#

mhm

#

i see i see

winged lintel
#

how're you feeling?

fiery sail
#

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

winged lintel
#

it is. this was a fun puzzle as well

#

do you understand the solution I suggested?

fiery sail
winged lintel
#

that's alright

#

i have to go now

fiery sail
#

sure, take care, ill notify you when something happens cheerios!

winged lintel
#

sure, even if it's to tell me it worked.
happy to help. see ya

fiery sail
#

@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

winged lintel