0 votes
by (230 points)
closed by
Hello, I'm super new to Twine and am not at all proficient when it comes to coding and all that.

So basically, what I'm trying to do is set up a respect-points system for my story, in which you can gain a certain amount of respect from a certain person by picking specific dialogue options with them. And depending on how many respect points you have (since they'd stack up over time and progression in the story), new and exclusive dialogue options will be made available for said characters.

How would I go about this, since there would need to be different points for each character they interact with, not just one global point rank.
closed with the note: Solved!

1 Answer

+1 vote
by (2.4k points)

First you would need a variable to store the respect points. Declare it on your first passage or in StoryInit (an special passage that is executed when you launch your game). It would be something like this:

<<set $respect to 0>>

We declare it to 0 so we can add or substract from it later.

For the conversation itself there's several ways of doing it. One way could be using the <<link>> and <<replace>> macros like this:

<p>GUARD: Who's there?</p>
<div id="answer">
	<p>Your answer:</p>
	<<link "Your king!">>
		<<replace "#answer">>
			<p>YOU: Your king!</p>
			<p>GUARD: Your Highness! Sorry for bothering you!</p>
		<<set $respect += 1>>
	<<link "Shut up, pleb!">>
		<<replace "#answer">>
			<p>YOU: Shut up, pleb!</p>
			<p>GUARD: Yes, my lord! (Idiot...)</p>
		<<set $respect -= 1>>

That will give you two different options to answer (the <<link>> macros) each one with different effects. In both of them, we are using the <<replace>> macro to replace the options (encloses in a <div> element with id "answer") with what would be the rest of the conversation. Also in each <<link>> we are modifying the value of the $respect variable with another <<set>> macro.

Finally when we need to check how many respect points we have in order to unlock certain parts of the conversation, we can use an <<if>> or a <<switch>> macro like this:

<p>You heard two guards talking below your window.</p>
<p>GUARD 1: So, what do you think of our king?</p>
<<if $respect == 1>>
	<p>GUARD 2: He seems like a nice person.</p>
<<elseif $respect == -1>>
	<p>GUARD 2: I don't like him, he seems like a presumptuous man.</p>
	<p>GUARD 2: I don't know, I've never spoken to him.</p>

NOTE: This is a very simple example. You would need to use those two code fragments in differents passages in order to Sugarcube to properly update the value of $respect.

If you have any other question, just ask.

by (44.7k points)

Note: You'd probably want to modify that last bit of code like this:

<<if $respect >= 1>>
	<p>GUARD 2: He seems like a nice person.</p>
<<elseif $respect <= -1>>
	<p>GUARD 2: I don't like him, he seems like a presumptuous man.</p>
	<p>GUARD 2: I don't know, I've never spoken to him.</p>

That way values above 1 and below -1 would also be handled.

You could also handle responses like this:

You respond to the king with:
[[Of course, my lord.|Next Passage][$respect +=1]]
[[OK.|Next Passage]]
[[I'm afraid I'm busy.|Next Passage][$respect -=1]]

All of those links would take you to the passage named "Next Passage", however they each would change (or not change) the value of the $respect variable differently.

Hope that helps!  :-)

by (230 points)
So, that would be how you set up everything for a respect system with one person, right? So in order to have this present with multiple characters, what would I need to do for that?
by (44.7k points)
Simply use more variables.  You could either do one variable for each person, an array of values, or a generic object to hold all of the values.