

To better tell the story, I created a text box. I first learned how to do this using a YouTube video.
The video creates a rudimentary text box, which is good, but doesn’t meet my needs.



Characters
For better immersion, the text box needs the speaker’s picture and name. Sometimes the speaker changes; in my game, you have to click on the speaker’s hut tile to interact with them. A small animation was also added to the tile to give the overworld a bit more movement and life.
The character here is Pheus, whose hut is created in the center of the map right at the beginning of the game. He is the mentor in the story and helps Taja—the heroine—get back on her feet. His hut is directly in the player’s field of vision when they first start the game.

With an identifiable tile type I can also write a module that checks whether the player uses interaction when standing on PHEUS_HUETTE.
func checkForTalker():
if State.Map_Array[State.Shared_Player_Position.x][State.Shared_Player_Position.y] == "PHEUS_HUETTE":

This allows you to create multiple characters that are activated on different tiles.
I load the dialog itself from a JSON file. The dialog text blocks in the JSON file are indexed and broken down into text blocks that can be processed by the text box.
I used a JSON file to have a central location where the text output is stored, making it easier to change it during development.

Code Logic
Loading the text from the JSON file requires a small function that opens the file, copies the contents into a variable, and then closes it again.
ressource
here is the path to the JSON file.

Breaking down the text was a bit of a challenge, as it was initially broken down mid-word. I solved this with:
var lastSpace = clip48.rfind(" ")
rfind(" ")
searches for the last space and saves its position, later I simply made the fractions at this position.

I wrote the structure so that the texts the character says are indexed. For example, index 0 is the first sentence said to Taja at the start of the game:"Pheus": {
"0": "Ich bin Pheus, ich habe dich aus dem Wasser an der Küste gefischt und dir wieder auf die Beine geholfen!",
Later in the game I set milestones which are set after completing certain story beats, and these are then used to make progression in the dialogue.



Difficulties
Most of the difficulties arose from the sequence, i.e., when something should happens. For example, I had text output twice for a long time.
A lot of time passed before I realized that I was addressing the character again because I was standing on their space and using the action key to continue their text.
I tried to solve this by creating a switch that only returns to true when I leave the space. And a timer—which I ultimately kept—that prevents the address from being made for a few seconds.
The timer starts when the text has been read.