0 votes
by (170 points)

Hi,

I am using sugarcube 2.21 and am wanting to make a dialog system which is based around the value of a variable, which is changed over time, based on what a user selects.

The steps are as follows:

  • client makes a comment
  • three options are available that the user can respond with
  • upon selection, the client is either annoyed, happy, or remains the same.
  • if the client value reaches maximum or minimum, the scenario ends
  • if not, a new client comment/user response set is selected from a pool of three possibilities

Hopefully that explains what I am after. Just after some ideas about a good approach.

Thanks!

1 Answer

0 votes
by (44.7k points)
edited by

This is pretty straightforward to do with a variable.

First, you want to set a baseline.  So in your StoryInit passage you could put "<<set $Happiness = 50>>".

Then, in your story you want something like this in three different passages (Passage1, Passage2, and Passage3):

Text part of the passage where the customer speaks.

You could <<nobr>><<link action1>>
	<<set $Happiness -= 5>>
	<<if $Happiness <= 0>>
		<<goto BadEnding>>
	<<elseif $Happiness >= 100>>
		<<goto GoodEnding>>
	<<elseif random(1, 2) === 1>>
		<<goto Passage2>>
	<<else>>
		<<goto Passage3>>
	<</if>>
<</link>>, <<link action2>>
	<<set $Happiness += 5>>
	<<if $Happiness <= 0>>
		<<goto BadEnding>>
	<<elseif $Happiness >= 100>>
		<<goto GoodEnding>>
	<<elseif random(1, 2) === 1>>
		<<goto Passage2>>
	<<else>>
		<<goto Passage3>>
	<</if>>
<</link>>, or <<link action3>>
	<<if random(1, 2) === 1>>
		<<goto Passage2>>
	<<else>>
		<<goto Passage3>>
	<</if>>
<</link>>.<</nobr>>

Just change the text at the top for the customer's comment, the descriptions of the player's possible actions, and the passage numbers in the code so you don't go to the passage you're already in, and that should do the trick.

Also, read through the SugarCube documentation if you have any questions on the above code.

So, that's one really simple way to do it.  With the code I've given you above, it shouldn't be too hard to make it into a more complicated method if you wanted to.

by (170 points)
Hi,

yes, this looks like a good idea. Is there any ways that you could use arrays or something to organise all of the text. I have a lot of small passages which may be easier to manage.

Thanks,

Bruce
...