Author Topic: Dialog Box script with Name Displayed  (Read 398 times)

llamazing

  • Full Member
  • ***
  • Posts: 164
    • View Profile
Dialog Box script with Name Displayed
« on: November 23, 2018, 04:42:08 pm »
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)
« Last Edit: December 09, 2018, 01:48:50 am by llamazing »

alexgleason

  • Full Member
  • ***
  • Posts: 120
  • Vegan on a Desert Island
    • View Profile
    • Vegan on a Desert Island
Re: Dialog Box script with Name Displayed
« Reply #1 on: November 23, 2018, 07:27:30 pm »
This is very cool! Thanks for sharing. I might use this.
RIP Aaron Swartz

llamazing

  • Full Member
  • ***
  • Posts: 164
    • View Profile
Re: Dialog Box script with Name Displayed
« Reply #2 on: December 08, 2018, 06:27:50 pm »
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.