Dialog Box script with Name Displayed

Started by llamazing, November 23, 2018, 04:42:08 PM

Previous topic - Next topic
November 23, 2018, 04:42:08 PM Last Edit: December 09, 2018, 01:48:50 AM by llamazing
I wanted to have the name of the person speaking displayed in at the top of the dialog box, so I modified the dialog_box.lua script by Christopho (I used the one from Children of Solarus since it looked to be the most up-to-date version).




The new syntax for the dialog text uses a line beginning with '##' to specify the displayed name. Without any lines beginning with '##', no name will be displayed and the behavior of the text box is the same as it was before.

The name will also be applied to subsequent panes within the same dialog until it is changed by specifying a new name. Beginning a line '###' turns the displayed name off again.

Beginning a line with '##>' shifts the name over to the top-right side of the dialog box. This is useful if you want the player's name to appear right-justified while the names of all other NPCs are left-justified.

Finally, beginning the displayed name text with '&' signifies that the given name is actually a savegame variable key and its current value will be used for the name text that gets displayed (e.g. '##>&player_name').

Lines beginning with '##' must be the first line of a set of lines for a given pane.

Sample dialog text:
Code (lua) Select

dialog{ text = [[
##Hector
First Pane: Beginning the line with two
'#' characters causes the name Hector to
appear at the top of the dialog.
Second Pane: The name Hector continues
to be shown in subsequent panes as well.

Third Pane: Note the empty line above is
used to complete the previous pane for
it to have 3 lines of text (even empty).
###
Fourth Pane: Putting 3 '#' characters at
the start of a pane causes it to display
no name at the top of the dialog.
##>Player
Fifth Pane: The > immediately after the
'#' characters causes the name to be
shifted over to the right.
Sixth Pane: This can be useful to show
the player's name. In this case, the
text shown is literally 'Player'.
##>&player_name
Seventh Pane: Here the '&' character is
used to instead display the value of a
savegame_variable named 'player_name'.
]]}


The modified script (GNU GPL v3, originally by Christopho) is attached along with a modified version of dialog_box.png (CC BY-SA 4.0, originally by Metallizer & Olivier Cléro)

This is very cool! Thanks for sharing. I might use this.
RIP Aaron Swartz

I fixed a bug where I had forgotten to clear the displayed name when the dialog is closed, so the old name would appear when starting a new dialog if no name was specified.

The updated script can be found in the original post.

I implemented this in VOADI - thank you!

I was concerned that it would be hard to merge with my existing script (I modified it from Christopho's original) but Meld made it easy to see the diff side-by-side and click the changes over.

I'm excited to see the impact this feature will have on the quality of my dialogue.
RIP Aaron Swartz

Cool! Have any pics?

What other mods did you make to your dialog box script?

Here's an example:



I might change the way it looks later, just wanted to get it working for now.

My other changes:

- 3 line text rather than 2 line
- narrower box
- use item_1 instead of attack to skip

Some of my changes were stupid because I didn't fully understand the Solarus API when I made them. I'd like to go back and improve it.
RIP Aaron Swartz

wow, I'm sure this improvement will be a classic for Solarus. Thanks for sharing.

I'm considering including a 'photo' of the NPC in the dialog box (kinda like Golden Sun). This is making me question whether putting the NPC name directly in the dialog box is the best solution.

Rather than switching between speakers mid-dialog, there could be separate dialogs for each speaker in a conversation, each with their own properties.
RIP Aaron Swartz