0 votes
by (310 points)
Hi

I am setting up a converstation between a player and a NPC where the NPC gives some dialog and the player chooses a responce from a selection, so far so standard.  The way I am handling this conversation is all within 1 passage using a variable to track the responce and an array to track the progress of the conversation.  as I understand it, the page needs to reload to update the variables but doing this brings the user to the top of the passage so I am looking for a way to jump to the top of the new section of the conversation.

 

While i could use multiple passages at this point, later on relying on multiple passages per interaction will get unwieldly and make it difficult for the player to keep track of the interraction chain.

1 Answer

0 votes
by (23.6k points)

Well you could do it like this:

 

<<nobr>>

<<set $conversation to ["Hey. Long time no seen!", "How are you?", "I'm fine. Thanks."]>>

<<if $lastpass != passage()>>
    <<set $count = 0>>
<</if>>

<<set $lastpass = passage()>>

$conversation[$count] <br>

<<switch $count>>

<<case 0>>

[[Hi.|passage()][$count += 1]]

<<case 1>>

[[I'm good. How are you?|passage()][$count += 1]]

<</switch>>

<</nobr>>

 

by (63.1k points)
This is a good answer. Just to throw my two cents in, though, use passages like candy. Seriously. Your development will be way harder if you try to skimp on them. Passages are Twine's biggest strength. If you're worried about the player, I'd still use multiple passages to construct things and then just use some <<include>> macros.
by (23.6k points)

After thinking a bit more about this, this solution seems a bit overcomplicated, especially when it comes to depicting dialogue that branches out. In that case it would be better to set things up like this:

 

<<nobr>>

<<if $lastpass != passage()>>
    <<set $talk = "Hi, how are you?">>
<</if>>
<<set $lastpass = passage()>>

$talk <br>

<<switch $talk>>

<<case "Hi, how are you?">>
[[I'm great. How are you?|passage()][$talk = "I'm great too. Wanna hang out?"]]
<br>
[[I'm feeling miserable.|passage()][$talk = "What's wrong?"]]

<<case "I'm great too. Wanna hang out?">>
[[Sure thing.|passage()][$talk = "Let's head to the candy shop then."]]
<br>
[[Sorry I'm busy.|passage()][$talk = "Aw... Maybe next time then."]]

<<case "What's wrong?">>
[[I ate too much candy...|passage()][$talk = "Better lay down for a bit then."]]

<</switch>>

<</nobr>>

 

...