Page 1 of 1

Show Key Bindings in Dialog

Posted: Wed Nov 23, 2022 10:49 am
by tabtaste
Hey,

i want to show the actuel key binding from New input system as a turtorial with the Dialog Manager. I didnt find a good way. I tryed this but it dos not work.

is here a normal way to do it ?

Code: Select all

    public void OnControlChanged()
    {
        playerInput = GetComponent<PlayerInput>();
        inputActionJump = playerInput.actions["Jump"];
        if (inputActionJump.GetBindingDisplayString() == null){ return; }
        int i = 0;
        foreach (var item in dialogDatabase.variables)
        {
            if (dialogDatabase.variables[i].Name == "JumpKey")
            {
                if (inputActionJump.GetBindingDisplayString() == null) { return; }
                dialogDatabase.variables[i].InitialValue = inputActionJump.GetBindingDisplayString();
            }
            i++;
        }
        
    }

Re: Show Key Bindings in Dialog

Posted: Wed Nov 23, 2022 11:48 am
by Tony Li
Hi,

At runtime, think of the dialogue database as read-only. Don't change its variable's Initial Value. Instead, change the runtime value in the Lua environment using DialogueLua.SetVariable():

Code: Select all

public void OnControlChanged()
{
	playerInput = GetComponent<PlayerInput>();
	inputActionJump = playerInput.actions["Jump"];
	if (inputActionJump.GetBindingDisplayString() == null){ return; }
	DialogueLua.SetVariable("JumpKey", inputActionJump.GetBindingDisplayString());
}
Then you can use the [var=variable] markup tag in text:
  • Dialogue Text: "To jump, press [var=JumpKey]."

Re: Show Key Bindings in Dialog

Posted: Wed Nov 23, 2022 11:56 am
by tabtaste
WOW

thats grat!!!

can i also change the value "oncontrolchange" and refresh the text when i"m current in the dialog.

Something like "repeat/refresh current dialog subtitel text" with the new binding.

Re: Show Key Bindings in Dialog

Posted: Wed Nov 23, 2022 2:11 pm
by Tony Li
Hi,

Yes. Run this code:

Code: Select all

DialogueLua.SetVariable("JumpKey", inputActionJump.GetBindingDisplayString());
DialogueManager.currentConversationState.subtitle.formattedText =
    FormattedText.Parse(DialogueManager.currentConversationState.subtitle.dialogueEntry.currentDialogueText);
DialogueManager.standardDialogueUI.ShowSubtitle(DialogueManager.currentConversationState.subtitle);

Re: Show Key Bindings in Dialog

Posted: Thu Nov 24, 2022 3:11 am
by tabtaste
thats great! thanks a lot !!!

Re: Show Key Bindings in Dialog

Posted: Thu Nov 24, 2022 8:19 am
by Tony Li
Glad to help!