About weapons array problem...

Hi everyone! I planned making selective weapons system on my game. :slight_smile: But I look like making a wrong weapons fire code. :frowning: I need some help ! :cry:

Does it generate an infinite loop? Because the conditions of button click and cursor over button_mp5 should be true forever if you don’t move the mouse or delete the button_mp5 object :neutral_face:
Also, you’ll fire only while the cursor is on the button (because the fire events are inside the while loop), do you want it or you want to select a weapon (from its button) and then fire when click on any point of the screen? :slight_smile:

Lizard knows far more than I do about GDevelop, but it looks to me like you’re making it more complicated than it needs to be. If you just want to fire at a different bullet rate according to whether the button pressed is MP5 or AKS74U then just use two “IF” subevents. Something like:

Condition: Touch or Left button is down
 
 Subcondition 1: The cursor/touch is on button_mp5                                  Reset the timer etc.
                 The timer "MP5FireRate".....

 Subcondition 2: The cursor/touch is on button_aks74u                               Reset the timer etc.
                 The timer "AKS74UFireRate".....

Sorry look like I get wrong message. :stuck_out_tongue: I mean like below… :blush:

:exclamation: This is my problem, about wrong character and bullet direction I know to fix… :wink:

About While loops:
I see, well, you don’t need while loops (at least initially). While loops start and finish the loop instantly / in the same frame, for example if you do:

While: Left key is pressed Actions: Do + 1 to X position of Player
It will NOT move the Player 1 pixel every frame, but in the same frame, while the key is pressed, will move the Player. As the key pressed condition is true until the next frame at least, get ready for an infinite loop :wink:
Also, the while loops pause the game until the loop finishes, so if you face an infinite while loop the game actually freezes…

I don’t know how your example works :laughing: :
Now, in your events, it seems that the combination of “Mouse button down” + “Cursor is over Object” is so slow that you can release the click without generating an infinite loop warning (not sure actually), sincerely I have never faced such combination of pseudo-infinite while loops + timed child events to fire. Also if the cursor is not over the weapon button (button_mp5 for example) you should not be able to fire anymore, as the fire events are childs of the while loops, there are more events out there??? :confused:

A simple way to get it right:
1 - When you click the weapon button, set a variable = name of the weapon
2 - Check the weapon name saved in the variable and shoot that weapon

This way:

// Parent event 1
Conditions: Left mouse button down
Actions: None

        // Sub-event 1.1
        Conditions: Cursor is over button_mp5
        Actions: Do = "mp5" to text of variable Current_Weapon

        // Sub-vent 1.2
        Conditions: Cursor is over button_aks74u
        Actions: Do = "aks74u" to text of variable Current_Weapon

// Parent event 2
Conditions: Left mouse button down
            Text of variable Current_Weapon = "mp5"
            Timer "FireRate" is greater than 0.04 seconds
Actions: Reset timer "FireRate"
         Do = 1 to animation of character_mp5
         Create bullet at X;Y
         Move bullet

// Parent event 3
Conditions: Left mouse button down
            Text of variable Current_Weapon = "aks74u"
            Timer "FireRate" is greater than 0.04 seconds
Actions: Reset timer "FireRate"
         Do = 1 to animation of character_aks74u
         Create bullet at X;Y
         Move bullet

I can make a little example if you ask for it :slight_smile:

Lizard 13, you get’s function cannot work. This made me can’t weapon firing. :frowning: Can you show me example? :wink:

Sure, check this:
SelectWeapon.zip (83.6 KB)
If it is not what you need, please explain it again :slight_smile:

Hey Lizard 13, thanks :smiley: My problem was resolved, but had little bug on my project. :neutral_face: But look like I can fix it, if can’t fix, I will ask you again :blush: Anyway, thanks you again. :slight_smile: