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:
System ▶︎ On start of layout
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:
Keyboard ▶︎ On Z key pressed
Player ▶︎ Is overlapping Signpost at offset (8,0)
Player ▶︎ Is overlapping Signpost at offset (-8,0)
Player ▶︎ Is overlapping Signpost at offset (0,8)
Player ▶︎ Is overlapping Signpost at offset (0,-8)
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!