How to extract a String value from an Input? [SOLVED]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KindoSaurProductions

Hello there,

I am currently busy with a tutorial on how to make a Tournament Fighter game but sadly I’m stuck.

I know how to make a Combo System and I already have ideas on how to make code more generic for every possible fighter within your game. Yet I can’t get my head around receiving Inputs as a String.

With everything that I’ve tried, I only got as far as having an “integer” or weird long text describing in debug code what it needs to be.

What I want is an actual LETTER or WORD that is pressed, after which it can be stored within an Array which is then sent to a Dictionary as a KEY for the corresponding COMBO.

Here is a list of things that I’ve tried to get to the thing I want:
func _input(event):

func _input(event):

I tried entering the InputMap after a press was done and using that to get the correct input inside my array

And there are some other things that I have done to make this work. But became stuck again looping back to the issues I had before.

I also searched around the Internet for a definitive answer and did spot a forum post, which sadly would make my code no longer generic.

PS: I do know about the video of PigDev but it became really complicated after a short while

:bust_in_silhouette: Reply From: Inces

Am I getting this right ?
You want this dictionary to be something like { “upupdownpunchkick” : “spinning fire destruction kick”} ?

Then it seems You are only missing knowledge about string operands.
Name your actions accordingly in input map, and on input event() store whole (action) as a variable into combo array. This array will contain subsequent actions, so it will empty itself when too much time passes inbetween inputs. Now You just do NOT APPEND this array with strings of actions, but instead ADD those strings with + operator ! Result will be one long string easily usable as dictionary key.

Hey Inces,
close but not yet.

What I want is something in the lines of:

Player pressed this button → Key that is pressed, get its InputMap name (or actual Keyboard letter) → Register this inside a String → Place this inside an Array → Go to the next spot of the array → (After a few inputs or by running out of time) Stop and Send the Array to the Dictionary.

I am quite new for this side of Godot, since I am mostly busy with making the standard type of games that don’t use these mechanics.

PS: Thanks for helping

KindoSaurProductions | 2021-10-22 20:05

So You only have problem with extracting String from Input ? But didn’t You achieve this with event.as_text ? It literally returns words You used when naming input map. The same can be done with checking InputEventAction instead of InputEvent. You can also make it short and generic like this :

func Input(event) :

Still You should add strings together after completing array. ANd You shouldn’t use pressed KEYS, because it will make coding multiplayer ridicolous

Inces | 2021-10-22 20:37

True event.as_text() allows me to see the actual keyboard letters as well but the biggest drawback (which I don’t know the solution of) is that it also publishes/pushes the mouse pad and or other possible events that can happen during gaming.

In that sense, I am afraid that my game will break because I hadn’t spotted a special input.

Also, for now, I am not aiming for multiplayer but thanks for the heads up anyways =)

KindoSaurProductions | 2021-10-22 20:45

Oh, so You can make statement like this :

func input(event):
        if Input is InputEventAction :

it will filter events to your input map actions only, and it will all be strings

Inces | 2021-10-22 21:19

:bust_in_silhouette: Reply From: drumstickz64

You could loop through your actions in InputMap and check if your event matches any of them. If so, then append the action to the used_keys array.

func _input(event: InputEvent) -> void:
	for action in InputMap.get_actions():
		if event.is_action(action):