Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Godot Dialogue System 2

An advanced non-linear dialogue system for the free and open-source Godot engine. · By radmatt

Providing dialogue with context for calling methods and retrieving values

A topic by Xananax created Aug 27, 2020 Views: 239
Viewing posts 1 to 1

Hello! Great plugin.

I’m looking to use it in an RPG where talking with people might trigger actions on those people. For example, a person might be able to barter with you.

Or, a person may like/dislike you for saying certain things.

I know I can run global actions, but I would want to run methods in the context of the character you’re speaking to.

One way I’ve found to do this would be to have an autoload singleton like so:

# Interact singleton
var character

func dislike():
  character.love = character.love - 1

func open_barter_dialog():
  character.barter.popup()

Then, before starting a dialog, setting Interact.character = current_char, before Dialogue.start_dialogue.

Then, my script nodes can call dislike() and open_barter_dialog.

That works if every character has the same actions, but that means it’s very hard to call a specific command for a specific character.

A more flexible solution would be:

# Interact singleton
var character

func command(command_name: String, args: Array):
  if character.has_method(command_name):
    var func = funcref(character, command_name)
    funcref.call_funcv(args)

And then use in my scripts: command("invoke_devil", ["candles", "sulfur"]).

That seems overly cumbersome and very easy to get wrong.


Slightly different, but related:

How would I get local variables in text variables?

For example, I need a class of characters to change their text based on if they saw the player steal before or not. But each character individually tracks if they saw the player steal or not.

How can do: if current_character.<some value>: branch 1 else: branch 2?

Seems to me like the only way is also to set the character, then read character.has_seen_player == true. Which is ok, but also less practical than having access to a context.


Much easier for both problems would be to be able to do:

Dialogue.start_dialogue(json, character, context), where context is usable to call methods or retrieve values. The @ could be used to denote the local context, rather than global context. Otherwise, another character could be used.