This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Weapon switching script, firing works but reload doesnt

MuxuMuxu Posts: 4Member
edited June 2020 in Programming

Hey guys!

I am working on a 2D game with weapons.

I have a base weapon script here

https://pastebin.com/JEXXNB9J

And have a script for each weapon which extends the base weapon and has all the firing and reloading function in it.

Here:

https://pastebin.com/rWinRQFB

I am happy I got close to it working but somehow the reload only works when pressing the reload button, but not automatically when the clip is empty.

Maybe you get a better look into the problem.

Also I'd love to get any input on what you think of it and if I maybe use some bad habits or really inefficient or unusual stuff that stings in your eye

Ready new to it.

Thanks for any help!


Tags :

Best Answer

  • MuxuMuxu Posts: 4
    Accepted Answer

    Mh kinda sad the community isn't more active but I found the mistake myself!

    Problem was I always set the current_ammo equal to the clip_size which always filled the mag and thus it didn't need to reload.

    This was supposed to only happen on initializing so that's what I missed.

Answers

  • MuxuMuxu Posts: 4Member
    Accepted Answer

    Mh kinda sad the community isn't more active but I found the mistake myself!

    Problem was I always set the current_ammo equal to the clip_size which always filled the mag and thus it didn't need to reload.

    This was supposed to only happen on initializing so that's what I missed.

  • MegalomaniakMegalomaniak Posts: 2,580Admin

    You'd likely have gotten a reply or two if you had actually posted your code, or even just a snippet of it.

  • MuxuMuxu Posts: 4Member

    @Megalomaniak said:
    You'd likely have gotten a reply or two if you had actually posted your code, or even just a snippet of it.

    I posted a pastebin including it, didn't that work? Altho I see that using the built in function is cleaner and easier to look into.
    Point taken, wasn't meant as attack but it is sometimes hard on noobs looking for help.

  • MegalomaniakMegalomaniak Posts: 2,580Admin

    Ah, sorry. They do show up. I apparently had pastebin blocked on my end for some reason. Might be the case for some others as well, but shouldn't be the case for everybody.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @Muxu said:
    Mh kinda sad the community isn't more active but I found the mistake myself!

    I saw the post, I just didn't have the time to reply. :sweat_smile:
    I'm glad you figure it out though! And thanks for posting the solution, that should make it easier for anyone else who has a similar issue in the future :smile:

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.