Skip to content

IDialog

Carenalga edited this page Feb 11, 2023 · 5 revisions

Description

Use it to start branching dialogs. Is the shortcut for IDialog.gd, and can be used (from any script) with D (i.e. D.show_dialog('ChatWithGlottis') or D.ChatWithGlottis.start()).

Some things you can do with it:

  • Start a branching dialog.
  • Know when a dialog has finished, or an option in the current list of options is selected.
  • Create a list of options on the fly.

Examples

D.show_dialog('ConfirmAction')
D.show_inline_dialog(['Yes', 'Nope', "Don't know..."])
D.connect('dialog_finished', self, '_leave_room') # Calls the "_leave_room" method once the current branching dialog has finished

⬇️ Since version 1.9.0 ⬇️

D.ChatWithGlottis.start()

Properties

Signals

  • dialog_finished. Use this to finish a dialog tree. This will unlock the graphic interface.

  • dialog_options_requested( Array options ). Used by PopochiuDialog to notify that a list of dialog options (of type PopochiuDialogOption) may appear on screen. DialogMenu.gd connects to this signal in order to render those options.

  • option_selected( PopochiuDialogOption opt ). Used by DialogMenu.gd to notify that a dialog option opt in the current list was selected. PopochiuDialog connects to this signal in orther to call its option_selected method, which will be used in your scripts to react to that selection.

  • inline_dialog_requested( Array options ). Used to notify that a list of dialog options (of type String) may appear on screen. DialogMenu.gd connects to this signal in order to render those options. You don't need to call this directly. The show_inline_dialog method does this for you.

Public

  • active bool. true if there is a dialog tree currently in excecution.
  • current_dialog PopochiuDialog. Default null. A reference to the dialog that is currently playing.
  • prev_dialog PopochiuDialog. Default null. A reference to the dialog which was previously played.
  • selected_option PopochiuDialogOption. Default null. The option selected in the current options menu.
  • trees Dictionary. Default {}. Stores the status of all the dialogs in the game. It is used for saving/loading the game.

Methods

  • finish_dialog() void

    Emits the dialog_finished signal to stop the current dialog.

  • say_selected() void

    Makes the player-controlled character to say the option selected in the current options menu. Must be yield.

    func option_selected(opt: PopochiuDialogOption) -> void:
      yield(D.say_selected(), 'completed')
    
      match opt.id:
        'Hi':
          yield(_opt_Hi(opt), 'completed')
        'How':
          yield(_opt_How(opt), 'completed')
        'Exit':
          stop()
    
    _show_options()
  • show_dialog( String script_name ) void

    Starts the PopochiuDialog identified with script_name. The dialog tree will finish when the signal dialog_finished, in this script, is emitted. The list of dialogs in the Main tab shows the names you can pass to this method in order to start any of those dialog trees.

    idialog-dialog_script_names

    ☝️ Example list of dialogs for the project (in development) Buggy Adventure ☝️

  • show_inline_dialog( Array opts ) PopochiuDialogOption

    Shows a list of options (like a dialog tree would do) and returns a PopochiuDialogOption of the selected option. The IDs of this options will always be a String with text "Opt#" where # is a consecutive number starting at 1.

    func on_interact() -> void:
      yield(E.run([
        C.walk_to_clicked(),
        'Player: What should I do with this?'
      ]), 'completed')
    
      # This Resource is a PopochiuDialogOption.gd
      var opt: Resource = yield(D.show_inline_dialog([
        'Move it left',
        'Move it right',
        'Nothing'
      ]), 'completed')
    
      # The options ID will go from 1 to the size of the options passed prefixed by Opt
      match opt.id:
        case 'Opt1':
          E.run([
            'Player: ' + opt.text,
            'Player: Done'
          ])
          # TODO: Move the thing to the left
        case 'Opt2':
          E.run([
            'Player: ' + opt.text,
            'Player: Done'
          ])
          # TODO: Move the thing to the right
        case 'Opt3':
          E.run([
            'Player: Yeah, better to leave like it is.'
          ])

    D show_inline_dialog