Skip to content

Custom Yarn Commands

Claudia Libbi edited this page Aug 28, 2021 · 2 revisions

SetSpeaker

Effect: The next lines (until speaker is removed or replaced) are shown to be said by set speaker, so the speaker picture and name that were defined in the ‘’Speaker’’ object for the NPC are displayed in the dialogue. Note that in the Speaker object (explained below) you can set whether a speaker name should be known or unknown by default. If it's unknown, the name will appear as "???" until you don't use the command "SetNameKnown" (see below).

Use case:

<<SetSpeaker Lotte>>

(replace Lotte with desired NPC name)

Steps to take in Unity:

  • An object in the scene must be named ‘’Lotte’’ and have an NPC script attached to it.
  • The NPC script requires you to drag some components into the appropriate slots in the inspector window: type in the npc’s name, add a (Yarn) Dialogue Script and a Speaker object.
  • You want to create a new speaker object for your NPC in your assets by clicking: right-click>Create>Dialogue>Speaker. As you create this object, remember to give it the same name as your NPC. It will allow you to set an image for the speaker, too.

Use case 2:

<<SetSpeaker none>>

This will automatically set the speaker name to "Narrator" and the image to none.

SetNameKnown

Effect: Sets given name (of speaker) to known in the related speaker object. This results in the name being displayed (instead of "???" if a character is still unknown to the player) when "SetSpeaker" is used.

UseCase:

<<SetNameKnown Lotte>>

(replace Lotte with desired NPC name)

Steps to take in Unity: See steps for "SetSpeaker".

NoSpeakerPic

Effect: In some cases, you may not want to show the image of who is speaking, e.g. if the text isn’t actually spoken by anyone.

UseCase:

<<NoSpeakerPic ‘’>>

(it doesn’t matter whether you add ‘’ or something else, but Yarn will throw an error if you don’t give it any input.)

Steps to take in Unity: None

NoSpeakerName (a bit redundant, see SetSpeaker)

Effect: In some cases, you may not want to show the name of who is speaking, e.g. if the text isn’t actually spoken by anyone. Alternatively, you can also choose to set a different name or something like ‘’???’’ to communicate that the name is still unknown.

UseCase:

<<NoSpeakerName ???>>

(instead of ???, write whatever you want the name field to display)

Steps to take in Unity: None

HelperSays

Effect: To display text in the helper box, instead of the dialogue box, use this command.

UseCase:

<<HelperSays Here you write whatever you want the helper to say>>

Steps to take in Unity: None. Prerequisites should already be fulfilled, as Unity would throw an error if no helper text box was assigned in DialogUI. However, feel free to change the way it looks.

Energy

Effect: Change the player’s energy state from the dialogue, both up or down.

UseCase 1:

<<Energy -5>>

reduces player energy by -5. Energy can never go below 0. Reaching 0 triggers burnout state.

UseCase2:

<<Energy 3>>

increases player energy by 3. Energy can never go over set max-energy value.

Steps to take in Unity: None. Player script and Energy bar should be in the scene.

Relationship

Effect: Edit relationship status with an NPC. Relationship with player is a string value, so it is defined "qualitatively" rather than "quantitatively".

(Note: Due to the architecture of the game, some objects with NPC scripts are actually buildings/locations/objects. Theoretically, your player can have a relationship with them, too (but you can definitely just ignore this and never edit their relationship).)

UseCase:

<<Relationship thinks-you-are-weird Lotte>>

(replace "thinks-you-are-weird" with any other descriptive string. Make sure it is one string without spaces or adjust the implementation.)

Steps to take in Unity: An object named ‘’Lotte’’ with an NPC script as component has to exist in the screen (see SetSpeaker).

ItemToInventory

Effect: The name is a bit misleading, because the item will (with the current implementation) not actually be visible in the inventory afterwards. The main effect is that the object disappears from the scene by being set to inactive (be careful making objects inactive, if they have important scripts attached to them).

UseCase:

<<ItemToInventory Letter>>

(replace ‘’Letter’’ with the name of the object that you want to remove from the scene).

Steps to take in Unity: Scene must contain a game object with the exact name used as value. Make sure that there is only one object in the scene with this name.

SetAudio

Effect: Play audio track attached to an object with an audio source.

Use case:

<<SetAudio bg oceanwaves>>

(plays track "oceanwaves" from "background" audio source. If you want to set the audio from the audio source managing sound effects, use keyword "effect" instead of "bg". Replace "oceanwaves" with any audiotrack that you added to the respective audio source you want to play it from.)

Steps to take in Unity:

  • Your scene needs two objects with component "AudioclipManager", one for background music and one for effects.
  • Both need to be assigned to the respective public variable in the DialogUI object.
  • Make sure you added the clip you want to play to the respective audioclip manager.

AddXPCard

Effect: If the player reaches an important experience in the dialogue and should be rewarded with an experience card (XP Card), this command can be used to 1) show the card to the player, so they can collect it and 2) log that the card has been achieved, therefore adding the card’s XP points to the appropriate skill area (e.g. emotion card -> increase emotion XP), as well as adding the card to the inventory to be viewed again later.

Use case:

<<AddXPCard anger_lv1>>

(replace ‘’anger_lv1’’ with name of given card)

Steps to take in Unity:

  • You must have an inventory object (i.e. object with the inventory script) in your scene.
  • In this inventory component, you can add XPCard objects to a list. Make sure that the card you want to add with this command is dragged into this list.
  • To do so, you need to create a new Experience Card object. Similarly to the speaker object, click: right-click>Create>Experience Card. As you create this object, remember to give it the same name that you will use to call it later, as well as an image of the card, assign the correct skill XP and optionally add a description (currently not displayed anywhere).

LogEvent

Effect: This command helps keeping track of dialogue events that the player has already seen. To check later whether someone has already been to a part, you can log an event with (any) name.

UseCase:

<<LogEvent amy _angry_at_game>>

Steps to take in Unity: None.

SetBackground and RemoveBackground

Effect: Sets a background image for the dialogue and remove any image that is being displayed.

UseCase 1:

<<SetBackground imagename>>

(replace ‘’imagename’’ with your image name)

**Steps to take in Unity: **The image with the same imagename has to be added to the list ‘’Backgroundimages’’ in the DialogUI script component.

UseCase 2:

<<RemoveBackground ‘’>>

(‘’ can be replaced with anything, Yarn just needs an argument even though it isn’t used)

Steps to take in Unity: None.

DarkFilter

Effect: By default, the dark filter is on and creates a semi-translucent background for the dialogue, so the scene isn't too visible in the back. In some cases you might want the player to see the scene while the dialogue is shown, so then you can disable the filter.

UseCase:

<<DarkFilter off>>
<<DarkFilter on>>

Steps to take in Unity: Filter (canvas object) should be assigned to the DialogUI.

OpenChat, ChatMessage and CloseChat

Effect: These commands show, manipulate and hide a chat window UI during the dialogue.

UseCase:

<<OpenChat Jessica>>
<<ChatMessage Jessica: Hi!>>
<<ChatMessage You: Whatsuppp>>
<<CloseChat ''>>

(Chatwindow will appear and will be titled "Jessica". The text following "ChatMessage" will be displayed on a new line in the chatbox. "CloseChat" hides the window.)

Steps to take in Unity: Assign the respective (canvas) UI items for the chat window to the DialogUI object.

AddNewTask and RemoveTask

Effect: Manipulate task list displayed during gameplay to add new tasks and remove those that have been completed.

UseCase:

<<AddNewTask call mom>>
You added "call mom".
-> call mom
   <<RemoveTask call mom>>
   You've done it! Task complete...

(Example scenario showing how the task "call mom" is added to the task list - it should then be displayed in the correct UI element - and then, upon the player picking the option to fulfill the task, it is removed - it should then not be displayed anymore.)

Steps to take in Unity: Make sure that the UI element to display the task list is assigned to the DialogUI.

AddCopingStrategy

Effect: Similar to AddNewTask, a coping strategy (string) can be added to the object displaying coping strategies (some UI text object) from the Yarn dialogue.

See AddNewTask for further directions, it works in the same way (except no implementation for removing coping strategy once added).

TriggerScript

Effect: Trigger any script attached to a game object in the scene from the yarn dialogue. Note that to add a new script to trigger, you need to add a piece of code to the DialogUI script in the method: "TriggerScript" with a custom key to refer to when calling it.

UseCase:

<<TriggerScript intro_end>>

(uses the pre-defined key "intro_end" to execute the correct behaviour and trigger a certain script as defined in DialogUI.)

Steps to take in Unity: Modify behaviour by editing the code in the DialogUI (TriggerScript method).