Player using tools

Hi, I have events that will allow player to use tools by pressing Space key how do I prevent Space key being spam pressed? When I tried to press Space key repeatedly player will use the tool again even though is still in the process of using a tool, and the result is there will be more than 1 tool being used.

Hi, for the ‘space key is pressed’- condition you also need to add a ‘Trigger once while true’ - condition to make sure that the press on the space key is not registered more than once.
For limiting the number of tools that can be used at once, I would create a boolean variable (e.g. only if the variable is false a tool can be grabbed by the player).

Doesn’t work.

Still can use multiple tool at once.

Alright, first I would strongly suggest to simplify your events. In your case there is no need to have actions on key released. You can set the 3 boolean variables together in the create-object block.
You also don’t need ‘if all of these conditions are true’ as Gdevelop is only doing an action if the conditions that are put together in one block are all true anyway.

For toggling the state of the boolean variable this is all you need:

These events create a hoe once until the boolean object variable of player is toggled back to false (under whatever condition).
Just to clarify something: did you set the state of your boolean variables ‘At the beginning of the scene’?

I need the key release because the tool only will be used when the space key is released, when the space key is being pressed it will only create the tool.

I didn’t set the boolean state ‘at the beginning of the scene’ but I already set it at the ‘game setting’ ‘global variables’.

I see so I don’t need to add ‘AND’ if its still in one block, and if I also add sub event that’s mean action will be executed only if parent condition and sub conditions are true? Like a nested If statement?

This implies that someone is pressing the key for a long time and that during this time using the tool is not permitted. The ‘Trigger once while true’ condition makes it that each key press is only registered once. So with this condition you can keep pressing the key forever but nothing would happen until you press it again (but if the boolean variable ‘isUsingTools’ is not toggled, nothing would happen anyway). Creating the tool happens instantly and then you could just use it? - I still don’t see that you need the key release events, but I also don’t know how your game should actually work.

Yes, as you are using global variables, that makes sense.

That’s exactly how it works. :+1:

Rather than using the tools immediately after the space key is pressed, I want to make it like Harvest moon game where the tools is used after the button(in my case its space key) is released.
The difference between harvest moon and my game is Harvest moon used a single sprites of (player+tool) when using tools and my game use two sprites (player sprites and tools sprite), Harvest moon game just need to play specific animation when using tools and for my game I need to rotate the tools manually.

Well thanks and sorry for my bad english and explanation. I’ll just use simpler action (use tool instantly on key press) if its still not work.

Again this implies that you would press the space key for much longer than necessary for pressing a key (a few miliseconds). Anyway, you decide how to set things up and if they finally work the way you like everything is okay.

No need to be sorry for anything. :slightly_smiling_face: