Solarus Forum

Community => Your scripts => Topic started by: llamazing on November 23, 2018, 04:42:08 pm

Title: Dialog Box script with Name Displayed
Post by: llamazing 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
  1. dialog{ text = [[
  2. ##Hector
  3. First Pane: Beginning the line with two
  4. '#' characters causes the name Hector to
  5. appear at the top of the dialog.
  6. Second Pane: The name Hector continues
  7. to be shown in subsequent panes as well.
  9. Third Pane: Note the empty line above is
  10. used to complete the previous pane for
  11. it to have 3 lines of text (even empty).
  12. ###
  13. Fourth Pane: Putting 3 '#' characters at
  14. the start of a pane causes it to display
  15. no name at the top of the dialog.
  16. ##>Player
  17. Fifth Pane: The > immediately after the
  18. '#' characters causes the name to be
  19. shifted over to the right.
  20. Sixth Pane: This can be useful to show
  21. the player's name. In this case, the
  22. text shown is literally 'Player'.
  23. ##>&player_name
  24. Seventh Pane: Here the '&' character is
  25. used to instead display the value of a
  26. savegame_variable named 'player_name'.
  27. ]]}

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)
Title: Re: Dialog Box script with Name Displayed
Post by: alexgleason on November 23, 2018, 07:27:30 pm
This is very cool! Thanks for sharing. I might use this.
Title: Re: Dialog Box script with Name Displayed
Post by: llamazing 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.