Using instance variables to store and display dialogue

9

Attached Files

The following files have been attached to this tutorial:

.c3p

instancevariable-dialogue.c3p

Download now 165.7 KB

Stats

5,900 visits, 8,102 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 4 Dec, 2019.
.C3P

instancevariable-dialogue.c3p

Download now 165.7 KB

A very simple way of displaying different lines of text (aside from just shoving a load of different text objects on a layout) is to use instance variables. In this example, there is an NPC object which has an instance variable called ‘Dialogue’. It’s a string variable, so we can store some text in there to use later.

To actually get the text to show up, takes just one event. In broad terms, when a thing happens, show this NPC’s text. In order to make sure we’re picking the right one, the example file uses an ‘is overlapping’ condition. This means it should only use the instance variable associated when the NPC the player is overlapping. So:

Condition

Player ▶︎ is overlapping NPC

Action

Text ▶︎ Set text to NPC.Dialogue

Then, if you want the text to disappear when you’re not ‘talking’ to an NPC, you can use an Else:

Condition

System ▶︎ Else

Action

Text ▶︎ Set text to “”

This will set the text to nothing, so the text box will appear blank until you overlap with another NPC. And that’s all there is to this method! If you've only got a couple of objects that need to display unique text, or if you have many instances of one object that need to show the same text, this system should be ideal for you!

Next Tutorial In Course

Using an array to store and display dialogue 03:06

Building on the instance variable technique in the last tutorial, this tutorial looks at using an array to store dialogue text and instance variables to call the correct line of dialogue.

  • 6 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • But,how can I put text on the dialogue varaible to use it. I'm not smart at all in this. Learning slowly.edit: I just know now, how to add. Its to add in the initial value of string variable.

    • [-] [+]
    • 1
    • 1 points
    • (1 child)
    [deleted]
  • Not sure if this is a bug, or I am doing something wrong. INitially when I clicked each NPC box, the Dialogue instance variable value showed only "varies", later on just clicking around, all of a sudden I can see the value ie text content for each NPC box

  • This is very helpful. I now know how to display dialogue and the use of else. Arigato gozaimusss