So… it’s been a WHILE since I’ve put out a proper guide on how to make something… but I guess it’s better late than never, right? Anyways, today I’m going to teach you (and re-teach myself, since I actually originally developed the system a few months ago.) how you can create a scrolling-style dialogue system for in-game NPCs inside your map. Without further hesitation, let’s jump right into it!
Building the System
Properties
Before we can code anything, we’ll need to set up the values and behaviors of the properties we’ll need, and understand their roles.
4 properties are needed, those being:
-
d-info: This property simply holds the text that the system will pull letters from. Set this to be a text value.
-
dchar: This property essentially tracks which letter the dialogue has reached. Ex: If dinfo’s value is “Hello, I am cool.”, and the system has reached “Hello, I a”, then dchar would equal 10, since it has reached the 10th letter, including spaces and punctuation. Set this to be a number value with a default value of 1.
These are the settings:
-
dlength: This property adapts to the value of dinfo, it is used to let the system know when the text is done, because dchar and dlength would be equal. Set this to be a number value.
-
dchange: This property is incredibly important, as it is what is actually shown as the system is running. Set this to be a text value.
Devices
Now that we have the properties set up, we can lay out the devices we need to have this system function.
We’ll need 6 devices, among which are
-
A button, or something to trigger the system to run.
-
4 triggers, which you’ll see are doing most of the heavy lifting.
-
A text device, which will make the text show up for the player.
Now, for the REAL work…
The Block Coding
We’ll start with the first trigger of the four. This trigger is what makes the system more adaptable, since this starting trigger and a text device are all you need for each individual dialogue.
This trigger just sets the value of dinfo, so the block coding would simply be this:
Then we have the second trigger, which is the start of the actual system. Have this trigger when receiving on ‘textset’, so that it can update property values to match the new text. The coding would be this:
Now the third trigger, which will be wired to be triggered after the second trigger, like this:
Additionally, have it trigger when receiving on ‘DIA’. You’ll see why here in a second.
This is the block coding that will actually power the updating of the dialogue itself. I’ll show you what the code looks like altogether, then I’ll break it down step by step so you can understand what’s going on.
Might look a little overwhelming at first, but I can assure you, it’s a lot more simple than you think.
We’ll start at the top, with this if--> do
block. By checking if dchar(the letter the system has updated up to) is equal to the length of dinfo (the length of the full text), it’s figuring out if the system has shown the full text. If it has, then it’ll broadcast on a channel(END TEXT) that will tell the system to stop, and will deactivate this trigger using the settings. (Have the trigger re-activate when receiving on ‘ACT’ and deactivate when receiving on ‘END TEXT’.
Otherwise, it’ll run the regular script to update the text.
First, it updates the value of dchar, simply increasing it by 1 more than what it was before.
After that, it uses the text that’s already been shown(red), and adds the next letter to the end(yellow), based on the new value of dchar.
After all that is done, it broadcasts a message on DIA, which will continue the loop.
And lastly, the final trigger. This is simply used as a reboot, which will re-activate the triggers for the next time they are used. The only things going on here are the settings:
Now that the triggers are all set up, we can move on to the last part, that being the text that shows up. Again, fairly simple. Have it run this block code when receiving on DIA
:
And that should outline all the components of this system.
Extra Note: When creating multiple dialogues, you only need to copy the first trigger, change the dinfo block inside, and add a new text device.
Thank you for reading this guide, please let me know if I neglected to explain any part of this system, because as I said, I originally created this a while ago.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10