Skip to content

Using keywords

Felix Naumann edited this page Feb 18, 2022 · 1 revision

Keywords are sequences typed by the player involved in the conversation which do not affect the flow of the conversation. If typed they count as no input for the conversation flow.

Keywords are a feature not present in the regular conversation api. The closest thing it has is the string you may define as an escape sequence for the user to able to prematurely abandon the conversation by typing the sequence.

RicherConversation takes this up a notch. Currently there are two predefined keyword actions ready to be used.

Going back

The user involved goes one step back in the conversation. The question from the last prompt will be asked again. Prompts which don't involve any input from the user are skipped when going back (or until the beginning of the conversation is reached).

In the example below I have three prompts asking basic questions. The user may go back to a previous prompt using either of the two defined go-back keywords.

RicherConversation conversation = new RicherConversationFactory(this)
        //define a prefix using BaseComponents
        .withPrefix(context -> new TextComponent(new ComponentBuilder()
                .append("[")
                .color(SECONDARY_MAIN_COLOR)
                .append("ExamplePlugin")
                .color(MAIN_COLOR)
                .append("] ")
                .color(SECONDARY_MAIN_COLOR)
                .create()))
        //define a go-back keyword
        .withGoBack("back", new TextComponent(new ComponentBuilder("Can't go back.")
                .color(SECONDARY_MAIN_COLOR)
                .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder("No, really!")
                        .color(HIGHLIGHT_COLOR)
                        .create())))
                .create()))
        .withGoBack("undo", new TextComponent(new ComponentBuilder("Sorry, can't undo the first step.")
                .color(SECONDARY_MAIN_COLOR)
                .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder("It's just not undoable...")
                        .color(HIGHLIGHT_COLOR)
                        .create())))
                .create()))
        //define first prompt
        .withFirstPrompt(new NamePrompt())
        //building conversation
        .buildConversation(player);
conversation.begin();

Showing history

The user is presented with a (custom formattable) history of prompts and answers.

RicherConversation conversation = new RicherConversationFactory(this)
        //define a prefix using BaseComponents
        .withPrefix(context -> new TextComponent(new ComponentBuilder()
                .append("[")
                .color(SECONDARY_MAIN_COLOR)
                .append("ExamplePlugin")
                .color(MAIN_COLOR)
                .append("] ")
                .color(SECONDARY_MAIN_COLOR)
                .create()))
        //define a history keyword and skip non-blocking prompts
        .withShowHistory("history", (promptAndAnswer, context) -> new TextComponent(new ComponentBuilder()
                .append("Question: " + promptAndAnswer.prompt().getPromptText(context))
                .color(QUESTION_COLOR)
                .append(" Your answer: " + promptAndAnswer.answer())
                .color(SECONDARY_MAIN_COLOR)
                .create()),
                true)
        //define first prompt
        .withFirstPrompt(new NamePrompt())
        //building conversation
        .buildConversation(player);
conversation.begin();

Clone this wiki locally