How to wait for a user input (mouse click)

Howdy everyone! I am semi-new to Godot and have a decent level of programming experience but I am still learning. The biggest hurdle I am trying to overcome is the organization and methods to use for creating my projects. Usually I use guess and check, trial and error strategies but this is very time consuming and demoralizing. Also research videos online for code for exactly what I am trying to accomplish seems impossible as everything I stumble upon is helpful but not the exact case scenario, which is what has brought me here.

In short, I am working on a 2D project where two players will draft select a team roster from a selection of characters. The two players will face off with their squads in turned based combat. There will be a planning phase where each character will choose a command until all characters from both teams have selected an action with targets. Then all actions will occur simultaneously. The game will proceed until only one side is remaining.

The portion where I am stuck currently is with the selection of my buttons. I want to be able to select a button, and then have the game ask for a target location/selection.

For example:
I select “move” which emits a signal

I want the game to ask “where to move” so I can plug that value into moving that character

I have tried using await to run a function to do this, but the function runs anyway when I hit the “move” button and emits a signal back, which tells me it would work.

What are the syntax/api calls to use to wait for an input(mouse click)? Or is there something bigger that I need to craft in order to accomplish this?

Can’t you use a kind of state / transition diagram ? Like :

  1. Game is in WAIT state
  2. Click on a “fighter” : mode is set to MOVE
  3. When in move state, either you only allow clicking on empty spaces (that triggers the move and returns to WAIT state) or you also allow clicking on other fighter to change the moving fighter.
  4. after each move, store the number of fighters that already moved. When all moved, start the fight and restart all.
1 Like

Thank you for the quick reply, this was very helpful and I have made progress. The issue I am having now is in trying to detect when the characterBody2D has finished moving and sliding…

From the select move state, I can then start physics process delta, where I click to move_and_slide(). However, when I go to emit the signal to flip back to the select move state, the characterBody2D only moves for a brief moment (because the exit state function says physics_process(false)) and then when I select move the second time it then finishes the move_and_slide when the state enables it again.

Is there a better method or some syntax I can use to detect when to send the finished_state signal?

Can’t you use a logic like while (character.position != target.position) ?