How do you await until the player presses enter?

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

I have a dialogue system that prompts multiple options that each branch off into more options and so on… (Kind of like Fallout)
I want to await for the player to press enter on the keyboard before continuing the syntax

Example:

Go A or B?
	await(#player pressed enter)
if go A
	Go C or D?
	await(#player pressed enter)
	if....
	elif....
elif go B
	Go E or F?
	await(#player pressed enter)
	if....
	elif....

why no something like

var option_chosen

if player pressed enter
{
        if A == option_chosen
         {
          //do something
         }
         else if B == option_chosen
         {
             do something else
         }
       
}

Moreus | 2023-04-10 08:19

I don’t put this as answer because you will vote down me like last time with almost same question. You just hide your last questions.
this how you tread people who try help you.

Moreus | 2023-04-10 08:30

The response you gave previously had very poor grammar and spelling and was therefore unintelligible.
I am very grateful for the help but obviously, if it is written in severely broken English, without even taking the time to go to Google Translate, it is not helpful. I digress.
I removed the previous question because it was not formulated well on my part.

The problem with this approach is that if option_chosen = C, then it will not pass if A == option_chosen because the option is C, not A.

var option_chosen

if player pressed enter
{
	if A == option_chosen
    {
          	if C == option_chosen
         	{
            	//do something
         	}
         	else if D == option_chosen
         	{
             	do something else
         	}
    }
    else if B == option_chosen
    {
    	do something else
    }

}

Scorch | 2023-04-10 11:33

Not sure what you talking about. If you don’t understand answer ask for more.
You needed classes or structs for your dialogues.
Why You hardcode all dialogues?
I can suggest json
JSON — Godot Engine (stable) documentation in English

demo of dialog in json:

{
  "id": 1,
  "message": "Hi there! How can I help you?",
  "options": [
    {
      "id": 2,
      "text": "I'm looking for information on your products.",
      "destination_id": 3
    },
    {
      "id": 3,
      "text": "I have a problem with my order.",
      "destination_id": 4
    },
    {
      "id": 4,
      "text": "Never mind, I was just browsing.",
      "destination_id": null
    }
  ]
},
{
  "id": 3,
  "message": "What kind of products are you interested in?",
  "options": [
    {
      "id": 5,
      "text": "Electronics",
      "destination_id": 6
    },
    {
      "id": 6,
      "text": "Clothing",
      "destination_id": 7
    },
    {
      "id": 7,
      "text": "Furniture",
      "destination_id": 8
    }
  ]
},
{
  "id": 4,
  "message": "I'm sorry to hear that. Can you tell me more about the problem?",
  "options": [
    {
      "id": 8,
      "text": "My order hasn't arrived yet.",
      "destination_id": 9
    },
    {
      "id": 9,
      "text": "The product I received was damaged.",
      "destination_id": 10
    },
    {
      "id": 10,
      "text": "I received the wrong product.",
      "destination_id": 11
    }
  ]
}

Moreus | 2023-04-10 13:22

2 Likes
:bust_in_silhouette: Reply From: gate120

You can try this:

if xxx :
    dosomething....
    await Events.wait_confirmation # await until the signal emits
    ....something else

Events is an autoload singleton, it has a signal called wait_confirmation, then handle a input event to emit it.

1 Like
:bust_in_silhouette: Reply From: Scorch

Here is the functionality I wanted. I had a hard time finding documentation of await, but I found it and was able to resolve my question.
Documentation: GDScript reference — Godot Engine (stable) documentation in English

signal pressedEnter

func _input(event):
	if event.is_action_pressed("enter"):
		pressedEnter.emit()

#Go A or B?
await pressedEnter
if go A
    Go C or D?
    await pressedEnter
    if....
    elif....
elif go B
    Go E or F?
    await pressedEnter
    if....
    elif....
4 Likes