Discuss Scratch

Janwyn
Scratcher
35 posts

Dialogue Engine

Dear Scratchers,

I want to build a dialogue engine that can:

  1. Read lines from a list
    Display them on cue
    Wait for a time depending on the line's length
    Pause between lines
    Handle interruptions

The engine would help me write dialogue for my coming sequel to my recently-released game Journey to The Moon, whose linear, hand-coded dialogue was so painful to create that I want to write the next game's dialogue with an engine that runs from a loop.

A traditional list-and-loop dialogue solution works only for two characters: I want to write scenes with at least three speakers. Therefore, I need a non-traditional list-and-loop solution, but I do not know how to make my characters wait their turn to speak–or even how to control the length of time a line is displayed. Can anyone help me?

Sincerely,
Janwyn
bjskistad
Scratcher
1000+ posts

Dialogue Engine

Do you want pen or clones? There are multiple text engines out there… It just depends what you want…
SkyShine
Scratcher
100+ posts

Dialogue Engine

If you want a pen text engine you can use this one by @djpro. If you are looking for a simple text engine you can use this one by @DeltaLimp.
Janwyn
Scratcher
35 posts

Dialogue Engine

@bjskistad
@SkyShine

I should have been clearer. I have several sprites, each representing one character, each of whom has lines to read from a script like actors in a play. I want an engine that will control who says what, when, and for how long, preferably with each character reading from the same script.
BKFighter
Scratcher
1000+ posts

Dialogue Engine

Janwyn wrote:

@bjskistad
@SkyShine

I should have been clearer. I have several sprites, each representing one character, each of whom has lines to read from a script like actors in a play. I want an engine that will control who says what, when, and for how long, preferably with each character reading from the same script.
Sprite 1
whenIreceive1saywhateverfor2secsbroadcast2
Sprite 2
whenIreceive2saywhateverfor2secsbroadcast3
Sprite 1
whenIreceive3saywhateverfor2secsbroadcast4
Sprite 3
whenIreceive4saywhateverfor2secsbroadcast5
Sprite 1
whenIreceive5saywhateverfor2secsbroadcast6
Sprite 4
whenIreceive6saywhateverfor2secsbroadcast7
Sprite 3
whenIreceive7saywhateverfor2secsbroadcast8
and so on…
bjskistad
Scratcher
1000+ posts

Dialogue Engine

BKFighter wrote:

Janwyn wrote:

@bjskistad
@SkyShine

I should have been clearer. I have several sprites, each representing one character, each of whom has lines to read from a script like actors in a play. I want an engine that will control who says what, when, and for how long, preferably with each character reading from the same script.
Sprite 1
whenIreceive1saywhateverfor2secsbroadcast2
Sprite 2
whenIreceive2saywhateverfor2secsbroadcast3
Sprite 1
whenIreceive3saywhateverfor2secsbroadcast4
Sprite 3
whenIreceive4saywhateverfor2secsbroadcast5
Sprite 1
whenIreceive5saywhateverfor2secsbroadcast6
Sprite 4
whenIreceive6saywhateverfor2secsbroadcast7
Sprite 3
whenIreceive7saywhateverfor2secsbroadcast8
and so on…
This is great for a conversation, but not reading text…
Janwyn
Scratcher
35 posts

Dialogue Engine

@BKFighter

I used something like that before, waiting until a variable called Line equalled a value hand-coded for each line, and broadcasting a message called Conversation after the talking. But I write so much dialogue that this process is bothersome: I want to write my lines into a list variable and have my characters read them. The progam that would control their line-reading I call a dialogue engine.

asivi
Scratcher
1000+ posts

Dialogue Engine

Have yo got a txt file with a script like this?
-character 1
How are you?
-character 2
I'm fine, thanks.
-character 1
Your kitten, is fine too?
-character 3
Miauuu!

If it's so then you can import it to a list. I think that the code for management is not hard.
asivi
Scratcher
1000+ posts

Dialogue Engine

Have yo got a txt file with a script like this?
-character 1
How are you?
-character 2
I'm fine, thanks.
-character 1
Your kitten, is fine too?
-character 3
Miauuu!

If it's so then you can import it to a list. I think that the code for management is not hard.
Janwyn
Scratcher
35 posts

Dialogue Engine

asivi wrote:

Have yo got a txt file with a script like this?
-character 1
How are you?
-character 2
I'm fine, thanks.
-character 1
Your kitten, is fine too?
-character 3
Miauuu!

If it's so then you can import it to a list. I think that the code for management is not hard.

Thanks for the list-importing idea. I never knew you could do that. But what I still don't know how to do is how to have each sprite read that script and decide, based on it, when to speak. Do you know how to do that?
asivi
Scratcher
1000+ posts

Dialogue Engine

If you refer to the amount of time to display each sentence it can be associated to the length of the text.
If the character has to do some action before speaking it can be performed by using variables or broadcasting messages.

Last edited by asivi (Dec. 16, 2015 22:57:47)

Janwyn
Scratcher
35 posts

Dialogue Engine

asivi wrote:

If you refer to the amount of time to display each sentence it can be associated to the length of the text.
If the character has to do some action before speaking it can be performed by using variables or broadcasting messages.

Thanks! I was thinking of controlling which character speaks when by prefacing their lines with their names and having each character speak only when the second letter of the line is his name's second letter (the first letter of two characters' names is the same) but I cannot omit the name from what the character says. I could maintain another list of names, having my characters check it and read from a name-less list of lines, but maintaining two lists would be quite unpleasant. Alternatively, I could interpolate the characters' names with the lines, but interpolations would only confuse me when I would write them. Any ideas?

EDIT: I could just create a new block called “Speak,” which would take an input number and read the associated line from the script, but a loop seems more-elegant.

Last edited by Janwyn (Dec. 16, 2015 23:40:04)

footsocktoe
Scratcher
1000+ posts

Dialogue Engine

For a dialogue, all you need to know is who is talking, what they are going to say, and for how long they will say it.

The way lists work is that if you import a text file you create yourself, then each line (between two carriage returns) will be one item in the list.

The idea above about controlling the time by counting how many letters in the line is good and it means you can use an ordinary playscript textfile.

If your textfile contains blank lines you could write in code to ignore them.

Your idea about using the first two letters in an item to determine the name is good. But if the playscript text file has the name followed by a colon, then it will be easy to detect the colon and use the rest of the line for the dialogue, while counting what comes before the colon as the name of the speaker. (Possible glitch: There is a colon in the line being spoken. Rare, but it could happen.)

I like this idea for a project so much that I will be working on my own version. I'll bookmark this topic to see how you are progressing and let you know what I come up with.
Janwyn
Scratcher
35 posts

Dialogue Engine

footsocktoe wrote:

For a dialogue, all you need to know is who is talking, what they are going to say, and for how long they will say it.

With the tools available in Scratch, knowing these things is no mean feat.

The way lists work is that if you import a text file you create yourself, then each line (between two carriage returns) will be one item in the list.

The idea above about controlling the time by counting how many letters in the line is good and it means you can use an ordinary playscript textfile.

If your textfile contains blank lines you could write in code to ignore them.

I might just do that one day, but for now, I'll use the list editor.

Your idea about using the first two letters in an item to determine the name is good. But if the playscript text file has the name followed by a colon, then it will be easy to detect the colon and use the rest of the line for the dialogue, while counting what comes before the colon as the name of the speaker. (Possible glitch: There is a colon in the line being spoken. Rare, but it could happen.)

I like this idea for a project so much that I will be working on my own version. I'll bookmark this topic to see how you are progressing and let you know what I come up with.

The second letter–not the first two. Good idea with the colon: every character's dialogue would have it in another place. But how would I remove the name and colon from the dialogue?
footsocktoe
Scratcher
1000+ posts

Dialogue Engine

Janwyn wrote:

Good idea with the colon: every character's dialogue would have it in another place. But how would I remove the name and colon from the dialogue?


That would be simple. When the list is being read by the code, it will be creating a variable called LINE for each item and a variable called NAME for each item.

Since each item will be read starting at the first letter, the letters go into NAME (using the JOIN block) until the colon is reached (using an IF THEN block to find the colon). Then the colon doesn't go into any variable, but now as the code continues to read through the letters of the item, it puts the rest of them in LINE.

When the end of the item is reached, then LINE is put in a SAY block which is given to the character NAME.

(An alternative would be to present the line as a subtitle at the bottom of the screen with the name still attached to it.)

Meanwhile, the list reader has incremented to the next item and when the time is up (time determined by the length of LINE just displayed) the process repeats again.

Last edited by footsocktoe (Dec. 17, 2015 10:31:51)

Janwyn
Scratcher
35 posts

Dialogue Engine

Thanks for the help, guys, and especially to MLTI-Conference, who made and posted this dialogue engine, a modified version whereof I will use in From Terra to Luna, my upcoming sequel to Journey to the Moon: https://scratch.mit.edu/projects/1075372/. I may also release the engine as a standalone project afterward because it supports acting via endcoded costume changes.
emmet2000
Scratcher
18 posts

Dialogue Engine

Dylan_TheBest7
Scratcher
3 posts

Dialogue Engine

Hey! if anyone wants to know, here is how to make the “when this sprite clicked” block more complicated.
whenclicked
foreveriftouchingmouse pointer?andmousedown?thenplaysoundmeowsetsizeto110%wait0.01secssetsizeto100%else
Thanks for reading!
Dylan_TheBest7
Scratcher
3 posts

Dialogue Engine

a
sorry

Last edited by Dylan_TheBest7 (Sept. 8, 2023 23:34:24)

Dylan_TheBest7
Scratcher
3 posts

Dialogue Engine

you can do

Sprite 1
whenclicked
sayaaafor2secs

Sprite 2
whenclickedwait2secs
sayaaafor2secs

Last edited by Dylan_TheBest7 (Sept. 8, 2023 23:36:29)

Powered by DjangoBB