Conversations - Paramecium13/LSN GitHub Wiki

LSN allows programmers to write conversations, which can be used to create more complex player-NPC dialog than can be created with simple choice structures.

Conversations can be written in the file, not inside anything else, or inside a script class or script class state, where they will be treated like methods in that script class. WIP To see the syntax, look at the conversation in Test\src\Main.lsn

Conversations

A conversation consists of nodes, which represent a point where the player is presented with a list of options to select from. Nodes contain branches, which represent the aforementioned options.

To run a conversation, just call it like you would a function (or a method, if it's defined inside a script class). It can even have parameters!

A conversation's parameters are defined just like the parameters of a function, after the conversation's name and before the opening curly-brace. The conversation's parameters can be accessed by code anywhere in the conversation but, like the parameters of a function or method, their values cannot be changed. Unlike functions, conversations cannot have return types.

Conversation Start Block

The conversation's start block is run when the conversation starts.

Variable Declarations

A conversation can declare variables using regular let statements (outside of the start block). These variables can be accessed by any other code in the conversation (the conversation's start block can only access variables declared before it), such as branch conditions and actions.

Nodes

The node whose declaration starts with auto (I'll probably change that to start later) is the first node to run when the conversation starts. If no node is marked with auto, the one listed first runs first.

When the conversation enters a node, that node's start block is executed. Then a list of choices is displayed to the player and the action corresponding to the player's selection is executed. If the current node has not been changed in the action, a the list of choices for that node is again displayed (but its start block does not run again).

Start Block

A node's start block runs when the node is entered...

Branches

A branch represents an option presented to the player. It consists of the text to show the player, an optional condition to determine if it should be shown, and a response that runs if the player chooses it.

Prompt

A branch's prompt is the text that is displayed to the player for that branch. Currently it must be a single expression, which, of course, must be of type string.

Condition

A condition is a boolean expression that determines whether or not the branch will be displayed to the player. If the branch has no condition, it will always be displayed. Like the prompt, the condition must be a single expression, which evaluates to a bool.

Action

The branch's action is the code that runs if the player selects that branch. It can contain any code you could put in the body of a function. To go to a different node, actions can contain a set node statement. If the action does not contain a set node statement or if no set node statement was executed, then the conversation will return to the branch's containing node at the end of the action.

In the action, a return statement causes the code to return to the current node. Note that the current node is not necessarily the node containing the branch; a previous set node statement in the action may have changed the current node.

The end conversation statement is used to end the conversation. Without it, the conversation will last forever!