Forum rules - please read before posting.

Referencing the parent/previous Action from a custom Action

Hi there!

The problem I have is that whenever I override what is suppose to happen when the player selects a dialogue options (of a "Start conversation" action), I find that I always adds a "Play speech" action with the exact same text as the dialog option. This gets kind of tedious..

My first idea was to create a custom action "Play dialog speech" that derives from ActionSpeech. The idea was to check it's "parent" action (the previous action in the action list) to get to the label of the dialogue option. But I can't seem to get a reference to my parent action in the Run method...

My second idea was to get to the parent action by accessint the currently running action list through KickStarter.actionListManager, and check the currently active action index (and grab the previous one). But I can't get hold of the currently playing list because it's private...

My third idea was to instead create a custom action that derives from the "Start conversation" action and somehow see if I could intercept the logic for generating a new option there (setting the text of the new action to the label of the dialogue option). But I'm not sure where (if anywhere) I would intercept this logic.

So all my ideas have failed so far :) Any ideas?

Comments

  • Welcome to the community, @kloot.

    The reason this is not done automatically is because the Dialogue: Play speech Action contains much more data than just the speech text itself.  Audio references, translations, animation and wait times etc are all involved - and such information would be lost if pulled from the Conversation itself.

    I should think this could be customised however through use of custom events - specifically OnClickConversation, which is run whenever an option is chosen and contains parameters for both the Conversation and the chosen option.  This can be used to extract said option's text, i.e.:

    private void My_OnClickConversation (Conversation conversation, int optionID)
    {
      foreach (ButtonDialog option in conversation.options)
      {
        if (option.ID == optionID)
        {
          string label = option.label;
        }
      }
    }
  • Thanks for your quick response @ChrisIceBox!

    My custom speech action that runs after each dialogue option inherits from ActionSpeech so all metadata that you mentioned is actually taken care of, I just want to set the messageText automatically.

    The OnClickConversation event you mentioned isn't fired if the option is overridden (which they need to be), and even if it was I don't know how to get hold of the currently active Action which I would need to set the messageText field in the next Action.

    I suppose I could loop through all action lists before a scene starts and find all instances of speech actions that appear directly after a conversation action and if their messageText is empty I could set it to the same value as the preceding label, but this seems like a rather heavy handed thing to do in run time :)
  • I'll investigate the OnClickConversation event issue.  The OnMenuElementClick event may also be appropriate.

    Indeed, iterating through ActionLists / Actions isn't ideal - but it's not even necessary to rely on a custom Action if things are simple.  If translation, audio etc isn't involved, it's perfectly fine to initiate a speech line through script:

    AC.KickStarter.dialog.StartDialog (myCharacter, "My speech text");

    Where "myCharacter" can be replaced with "KickStarter.player" to refer to the current player.

    What you could then do is have an Action e.g. wait a given time, or a custom one that waits for a given character to stop speaking.

    Another option (in theory) would be to hook into the OnStartSpeech event and override the display text itself after a "dummy" line has been invoked as normal.  If your speech text isn't scrolled, you can:

    1. Use OnClickConversation (once fixed) to determine the correct label
    2. Have your first response Action be a Dialogue: Play speech Action with dummy text.
    3. Listen to the next OnStartSpeech event and override the displayText of the Speech class:
    void OnStartSpeech (Char speaker, string text, int lineID)
    {
      if (text == "Dummy text")
      {
        Speech speech = KickStarter.dialog.GetLatestSpeech ();
        speech.displayText = myOptionLabel;
      }
    }
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.