Show Key Bindings in Dialog

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
tabtaste
Posts: 16
Joined: Fri Oct 07, 2022 11:46 am

Show Key Bindings in Dialog

Post 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++;
        }
        
    }
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Key Bindings in Dialog

Post 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]."
tabtaste
Posts: 16
Joined: Fri Oct 07, 2022 11:46 am

Re: Show Key Bindings in Dialog

Post 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.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Key Bindings in Dialog

Post 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);
tabtaste
Posts: 16
Joined: Fri Oct 07, 2022 11:46 am

Re: Show Key Bindings in Dialog

Post by tabtaste »

thats great! thanks a lot !!!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Show Key Bindings in Dialog

Post by Tony Li »

Glad to help!
Post Reply