Dialogue System Template (Templates)

Discuss Scirra's 2D Asset Store

Post » Sun Nov 06, 2016 8:04 pm

@Magistross Hello again! Hoping you could help me out to fix this.

How can I adjust the text either to be centered or to be close to the "rightside" portrait.

Image

Doesn't feel good at all. I'd like to adjust the text to the right side whenever the right portrait character speaks. Either that or center the text for every dialogue line.

Hopefully you could point me in the right direction! Thanks
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sun Nov 06, 2016 8:18 pm

Hi @Smileh, this shouldn't be too hard.

You can easily center the text of every line by adjusting the horizontal aligment of the SpriteFont object to center and be done with it.

But if you want it to adapt according to which side is the portrait, simply add a "Set horizontal alignment to right" on event 16 (under the "Set Mirrored" action). I would also make sure the spritefont revert to the default left aligment by adding a "Set horizontal alignment to left" on event 12.
B
58
S
23
G
22
Posts: 890
Reputation: 16,790

Post » Sun Nov 06, 2016 8:38 pm

Magistross wrote:Hi @Smileh, this shouldn't be too hard.

You can easily center the text of every line by adjusting the horizontal aligment of the SpriteFont object to center and be done with it.

But if you want it to adapt according to which side is the portrait, simply add a "Set horizontal alignment to right" on event 16 (under the "Set Mirrored" action). I would also make sure the spritefont revert to the default left aligment by adding a "Set horizontal alignment to left" on event 12.


Thank you @Magistross. I tried the center aligment before and it didnt work but it was because other reasons, so when I fixed that stuff forgot to test that again lol. Sorry and thanks for the help!

Now also, is there a way to adjust the margin just for the up and down, and not the right and left? I explain myself.

Image

I need to set the dialogue margin to 8 so the portrait is centered, but then it wont fit 2 lines on text. So how can I adjust for example the margin to 8 for the sides and to maybe 4 for top and bottom sides.
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sun Nov 06, 2016 9:28 pm

The size of the spritefont is set on event 12.

Here's the formula for the height : DIALOGUE_HEIGHT - DIALOGUE_MARGIN * 2 + DIALOGUE_LINEHEIGHT

If your spritefont's lineheight property doesn't fit 2 times in that, only one line will ever show. You could either tweak the variable values, or the change the formula so it uses a new variable with a value distinct from the DIALOGUE_MARGIN.
B
58
S
23
G
22
Posts: 890
Reputation: 16,790

Post » Fri Nov 11, 2016 8:48 am

Magistross wrote:The size of the spritefont is set on event 12.

Here's the formula for the height : DIALOGUE_HEIGHT - DIALOGUE_MARGIN * 2 + DIALOGUE_LINEHEIGHT

If your spritefont's lineheight property doesn't fit 2 times in that, only one line will ever show. You could either tweak the variable values, or the change the formula so it uses a new variable with a value distinct from the DIALOGUE_MARGIN.


Ok thanks, will see if I can make it work. One last thing!

If I set text alignment to the right, can I make the scrolling of the text also to change it's direction? It "grows" in a weird way.
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Fri Nov 11, 2016 1:56 pm

Smileh wrote:If I set text alignment to the right, can I make the scrolling of the text also to change it's direction? It "grows" in a weird way.

Unfortunately, that's how it works. Left align -> Text grows to the right, Right align -> Text grows to the left.

If you used a strictly monospaced font, maybe you could make it so the text becomes less and less appended with whitespaces so it looks like it grows to the right while still being right-aligned.

Code: Select all
"H          "
"He         "
"Hel        "
"Hell       "
"Hello      "
"Hello s    "
"Hello si   "
"Hello sir  "
"Hello sir !"

However that would require a rewrite of how the text is processed.
B
58
S
23
G
22
Posts: 890
Reputation: 16,790

Post » Wed Nov 23, 2016 8:54 pm

I made the below for my dialogue writer as a guide for when they write dialogue and scripted events. (Taken from the comments in the code.) Great plugin.

Dialogue text commands cheat sheet:
  • {pause}
    Force user to make an input for the current sequence to continue.

  • {wait:<delay>}
    Add a delay for the next character to display.
    <delay>: delay in ms

  • {setdelay:<delay>}
    Set the character delay for the current sequence.
    <delay>: delay in ms

  • {next}
    Automatically skip current sequence and go to the next. Use it at the end of a sequence, coupled with a wait command just before so the user can read. (Perfect for cutscene).

  • {end}
    End the current dialogue. Useful in a multiple forks dialogue.

  • {playsound:<filename>,<tag>}
    Play a sound file.
    <filename>: the sound filename without extension
    <tag>:tag

  • {playmusic:<filename>,<tag>}
    Play a music file.
    <filename>:the music filename without extension
    <tag>:tag

  • {fademusic:,<tag>,<duration>}
    Fade a music file.
    <tag>:tag
    <duration>: duration in ms to fade

  • {changeportrait:<animation>}
    Change portrait (only works if portrait is shown).
    <animation>: new animation name

  • {fork:<expression>, <truePath>, <falsePath>}
    Fork the current dialogue sequence into two possible path. Can fork inside the current dialogue or start a new one.
    <expression>: expression used to fork. Use the "GameVariables" dictionary for dynamic values. ex: {#goldAmount} >= 50. It will be evaluated with javascript "eval" function, so use valid javascript syntax. String litterals should be double quoted, and not containing any comma. String coming from the "GameVariables" dictionary should also be quoted. ex: "{#playerName}" == "Zelda".
    <truePath>: path if true, use a number to fork to another sequence index, or use a name to fork to a new dialogue. (A numeric value lesser or equal to 0 or an empty string will end the dialogue).
    <falsePath>: path if false, use a number to fork to another sequence index, or use a name to fork to a new dialogue. (A numeric value lesser or equal to 0 or an empty string will end the dialogue).

  • {choice:<choiceText0>::<choiceDiaglogue0>, <choiceText1>::<choiceDiaglogue1>, ...}
    Offer a choice of input to the user. Dialogue will fork according to the choice selected. One parameter per choice. If you need commas in your texts, escape them with a backslash (like this : \, ). Every parameter needs to end with ::"fork options" with "fork options" being a number to fork to another sequence index, or a name to fork to a new dialogue. (A numeric value lesser or equal to 0 or an empty string will end the dialogue) ex: {choice:Yes::saidYes,No::saidNo} -> Selecting the "Yes" choice would make me fork to the "saidYes" dialogue.
    <choiceTextx>: Choice menu text for for choice x.
    <choiceDialoguex>: target of fork to dialogue for choosing choice x.

  • {setvalue:<variable>,<value>,[operation]}
    Set a value inside the GameVariables dictionary.
    <variable>: key of value in GameVariables Dictionary object.
    <value>: value to set variable to.
    [operation]: (optional) = Operation to do on the value (must be numeric), if omitted, value will be SET. Possible values are : + - * /.
B
21
S
8
G
2
Posts: 41
Reputation: 2,520

Post » Thu Nov 24, 2016 4:22 pm

Nice doc! It indeeds can be handy to writers and scripters so they don't have to rummage through the capx! ;)
B
58
S
23
G
22
Posts: 890
Reputation: 16,790

Post » Sat Dec 10, 2016 10:47 pm

I just tried to add this to a fresh project and for some reason its not working- ive gone through and checked to make sure ive done things the same as previous files-

what is most likely the error if the box pops up and you can see the dialog- but the text just reads "text" instead of "o"

Looks like its not getting all the way through the dialogueEvents or something-

Trying to do something quick for Ludum Dare

Image
B
14
S
5
G
6
Posts: 64
Reputation: 4,243

Post » Mon Dec 26, 2016 1:00 pm

Hey @Magistross,

I was wanting to make a dialog system where the player builds a sentence from the options provided, and each path generates varying reactions from the NPC's. For example:

  • Haha! That's...
    • ...so funny!
    • ...the dumbest thing I've ever heard!
    • (back)
  • I'm not sure...
    • ...if that was supposed to be a joke or not.
    • ...you should talk that way about him,...
      • ...that's mean.
      • ...he might hear you.
      • (back)
    • ...I want to be around you, after hearing you say that.
    • (back)

and the respective sublist would only appear onscreen after the option in the previous list was chosen (with the "Back" option allowing them to undo their choice and go back to the previous list).

Any ideas how I would go about getting this system to work in the template?
B
16
S
4
G
4
Posts: 29
Reputation: 2,950

PreviousNext

Return to Scirra Store

Who is online

Users browsing this forum: No registered users and 1 guest