Im working on a simple POC thats centered on a turn-based battle system with reactive components (think Mario RPGs, Clair Obscure).
We’re all begginers, and so far we managed to get 2 parties fighting with some healing potions in the mix.
All syncronization is implemented using signals.
Implementing Items, we ran into a problem:
A popup menu item is generated for each of the party members usign shared infromation about the party resources (potions are shared).
Our targeting system is basically this
func _process():
if selecting_target:
select_target()
where select_target registers Input signals to move a cursor over the available targets, and select one pressing Enter.
The function executes every time the flag ‘selecting_target’ is true, looping until the player via keyborad inputs, selects a target and presses “ui_accept”, which sets ‘selecting_target’ to false, and emits a signal which triggers the rest of the appropiate behaviour and flow (heal/attack the target).
Problem is, when pressing “ui_accept”, specifically over the popup menu containing the potions, the keyboard signal does not release and is registered by select_target(), immediately selecting the first character under the cursor’s default position.
We solved it momentarily by inserting a brief timeout timer right after the pressed signal from the popup menu is registered, which gave time for the button signal to release.
This does not happen with the button assigned to the Attack command.
I have the feeling that handling the target selection as we are now will be troublesome for cases like this, more so when dealing with timing animations to user input for parry / dodge mechanics (not yet approached).
So i was wondering if there’s a better way to handle the diferent states of a turn that does not rely on _process, or gives us more control over the flow of the system.
I think it would be helpful to show either a clear video or picture of the problem because from your description I have no idea where and what you are trying to select.
Problem is, when pressing “ui_accept”, specifically over the popup menu containing the potions, the keyboard signal does not release and is registered by select_target(), immediately selecting the first character under the cursor’s default position.
Correct me if I’m wrong but the issue is that you have a shared input (ui_accept) that’s supposed to handle selecting items and selecting enemy target (for attack, magic, buff, debuff, whatever else) and this input prioritizes the wrong thing?
I think that implementing a state machine would be the first step. (if you haven’t already)
Then I would add a state specifically for selecting items, selecting targets attack menu, parry/dodge, quicktime events or whatever else you might need.
(if you have a lot of overlapping inputs it might be in your favor to make a state machine with nodes with specific scripts attached to them (see picture) that sets the other scripts processing mode to disabled as long as the player is not in said state)
for example, if the player is in “select_potion_state” then the “select_target_state” is not processing and can therefore not register the “ui_accept” input
Anyways thats how I would do it and i think that will also give you more control over your player
It sounds like your input is being consumed twice in the same frame by two different processes. Which input event are you using (if you are using events)?
I’m not sure because I’ve not run into this myself yet, but I think you need to use the unhandled input event and then mark it as handled when you first consume the event (making use of the 6th step of the input flow explained here: Using InputEvent — Godot Engine (stable) documentation in English).
I’m hoping to get some free time to spend on my own (barely started) turn based game project again soon, so I’ll probably be facing the exact same issue.