ID:1626462
 
(See the best response by Multiverse7.)
Problem description:
Well, not really a development problem, but I recently got interested again to start developing in DM again. Since I haven't done anything complex in DM for a while, I feel kind of rusty. I am also outdated on the changes that happened with animate(), maptext and so on.

But, let's go straight to my point. I am trying to make a dialogue system which is interface/HUD-based. What I am aiming for is a dialogue system that shows up, including a background, a mugshot of the character and obviously the text that has to displayed next to the mugshot on the background. A rough mock-up:


You can progress in the dialogue by pressing the space-bar and the dialogue system should also be able to display some sort of choice selection.
For example, the mob asks what your gender is, then you get another box above the top right of the original dialogue box with two options, male or female, which you can navigate with the arrow keys and then press the space-bar key to select that option. With an optional sort of arrow pointer that selects the current choice you have navigated to with the arrow keys. Another rough mock-up about this part:


How would I go about this? Involving maptext is what I have to do for sure, but I am not sure about how to handle the dialogue progression and displaying the next bit of text.

Also, is there any way to pull dialogues from .txt files which still uses dialogue progression. So lets say I have a block of text in that .txt file, but I don't want to show that block of text in one time, more like two sentences of that block, then press space-bar and the next two sentences follow.

Sorry for this long block of text you have to read, but I would appreciate any help/pointers/tips you can give me.

Thanks in advance
Raimo
Best response
I wrote this proc that should help you do what you want:
proc
/////////////////////////////////////////////////////////
// Breaks text into chunks based on the given length, //
// and returns a list of the pieces. //
/////////////////////////////////////////////////////////
breaktext(text, length)
if((!istext(text)) || (!length(text))) return
. = list()
if(!length)
. += text
else
for(var/pos in 1 to length(text) step length)
. += copytext(text, pos, pos + length)

Now what you can do is break up your text with that proc, and update the maptext with the next chunk whenever the space-bar is pressed. Does that make sense?
In response to Multiverse7
Multiverse7 wrote:
I wrote this proc that should help you do what you want: ...

Yeah, it does make sense, but wouldn't that proc be inconsistent. As in, not every sentence is as long, so wouldn't that sometimes result in words being broken off, etc. ?

Raimo wrote:
Multiverse7 wrote:
I wrote this proc that should help you do what you want: ...

Yeah, it does make sense, but wouldn't that proc be inconsistent. As in, not every sentence is as long, so wouldn't that sometimes result in words being broken off, etc. ?


If you made use of "findtext()" you could easily just have a code word of sorts that says "end of line" to the code. For example you could have something like follows:
proc/Get_Next_Phrase(Remaining_Text)
return(copytext(Remaining_Text,1,findtext(Remaining_Text,"{END_PHRASE}"))

Thus, if you input
"Hello, my name is Tom.{END_PHRASE}Welcome to my store!{END_PHRASE}"
into the proc it would return "Hello, my name is Tom.", you would then cut out the part you've read thus far and send the remainder next time you send to the proc.
Notably if you don't have your code word specified anywhere, it would return 0 on findtext, which by default will result in copytext() copying the entire string of text.

Just keep in mind you'll have to use number offsets for when you do the cutting based on the length of your code words.
In addition you could use such code words to trigger sounds and mugshot changes, allowing you to handle an entire automated conversation through reading a single text file rather than having to specify such things for each time you call for a conversation in the code.