Hi everyone! I planned making selective weapons system on my game. But I look like making a wrong weapons fire code. I need some help !
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
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?
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. I mean like belowâŚ
This is my problem, about wrong character and bullet direction I know to fixâŚ
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
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 :
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???
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
Lizard 13, you getâs function cannot work. This made me canât weapon firing. Can you show me example?
Hey Lizard 13, thanks My problem was resolved, but had little bug on my project. But look like I can fix it, if canât fix, I will ask you again Anyway, thanks you again.