Using an array to store and display dialogue

16

Attached Files

The following files have been attached to this tutorial:

.c3p

using-arrays-dialogue.c3p

Download now 164.15 KB

Stats

6,647 visits, 10,696 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

using-arrays-dialogue.c3p

Download now 164.15 KB

In this example, the dialogue will be handled using an array. Oh, and by the way, if a video is more your thing, then do check out this tutorial from Vimlark which was the inspiration for this tutorial!

By using an array, all text strings can be stored in one location and edited through the array editor. This means that if you’ve got lots of instances that need to show unique text, you don’t need to search the project for the specific instance you’re looking for. As long as you know which coordinates the text is stored in, (or even if you don’t) you can just pop into the array editor and change whichever line of text you want to. Or, if you suddenly decide you need more text strings, you can increase the size of the array from the array editor.

But how do you go about getting the data from the array? Well, first of all you need to make sure the game can access the project file. You’ll need to add the Array and AJAX objects to your project. Then add the following event:

Condition

System ▶︎ On start of layout

Action

AJAX ▶︎ Request project file (remember to pick your array file), tag “LoadDialogue”

System ▶︎ Wait for previous actions to complete

Array ▶︎ Load from AJAX.LastData

These events will ensure that your array is loaded into the project, which means you can now access the strings contained within it.

In the example file, the player object can use the Z key to ‘read’ signs. This happens by setting a text object to show the string contained in an array cell. The cell is set by using a pair of instance variables on the signpost object.

So, you need to use the following events to set the text:

Condition

Keyboard ▶︎ On Z key pressed

Sub-event Condition

Player ▶︎ Is overlapping Signpost at offset (8,0)

OR

Player ▶︎ Is overlapping Signpost at offset (-8,0)

OR

Player ▶︎ Is overlapping Signpost at offset (0,8)

OR

Player ▶︎ Is overlapping Signpost at offset (0,-8)

Sub-event Action

Text ▶︎ Set text to Array.At(Signpost.DialogueArrayX, Signpost.DialogueArrayY,0)

This event basically says that if the player is in the area around the signpost, and presses the Z key then show the text associated with that sign.

That is pretty much all there is to this system. But before we wrap up, that Array expression looks quite complicated, so let’s break it down a little:

Array.At is the expression for retrieving a value from a specific cell in the array.

The next part in the brackets tells the array what the coordinates of the cell are. In this case we’re using the DialogueArrayX and DialogueArrayY instance variables from the Signpost object, so you end up with (Signpost.DialogueArrayX, Signpost.DialogueArrayY,0). The zero is there because Construct 3 can handle 3D arrays, but we’re only using a 2D one here.

And that’s it! Go forth and try using arrays for dialogue!

Next Tutorial In Course

An introduction to JSON dialogue systems 07:28

JSON is a versatile option for creating dialogue within games, and this tutorial will get you started creating a basic JSON system.

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • The tutorial and the explanations are great ... I can't wait to try this myself.

    FixStar