+1 vote
by (210 points)
retagged by
Help!

I am still new to Twine and I am learning how the probability part works with the gaming platform.

Our goal is to link the users when they select the most of one option out of three total options.

So for example: Each question is labeled as A,B,C . When a user chooses more of one of those letters by the end of the game, we want to give them a specific ending.

How should we code that into the Harlowe 2 twine?

1 Answer

+1 vote
by (2.5k points)
What you are talking about is rather easy to do. You want each answer to be labeled A B or C if I understand correctly and if the player has more of one letter than the rest, the player will get that letter ending. If that is the case, all you need to do is create 3 variables labeled $a $b and $c (or whatever you want to do.) When the player chooses an answer that is labeled A. The $a variable will be given a point. Example:

Would you smooch a ghost?

(link:"Heck Yeah!")[(set: $a to $a + 1)(goto: "Question 2")]

(link:"Heck Yeah!")[(set: $b to $b + 1)(goto: "Question 2")]

(link:"Heck Yeah!")[(set: $c to $c + 1)(goto: "Question 2")]

At the end of the game the variable with the most points will determine the ending.

(If: $a > $b and $c)[(goto: "Ending A")]

(else-if: $b > $a and $c)[(goto: "Ending B")]

(else-if: $c > $a and $b)[(goto: "Ending C")]

Keep in mind that making links like this does not automaticly make the new passage, you have to make it and label it manually.
by (210 points)
So if I was to continue to the next questions, will the additional +1 change (to something like +2? or it varies on however we want to do it?)

 

For example:

Q3: Kissing a ghost is kind of like?

(link:"happiness!")[(set: $a to $a + 2)(goto: "Question 4")]

(link:"drugs!")[(set: $b to $b + 2)(goto: "Question 4")]

(link:"no!")[(set: $c to $c + 2)(goto: "Question 4")]
by (157k points)

@Glitchy (and @learningiscaring)

There is a logic error in the conditional expressions of your (if:) and (else-if:) macros, the expression $a > $b and $c doesn't equate the way you think it does. Because the expression contains the and operator it is first broken into two parts and then evaluated as follows:

(note: for the sake of this explanation I will assume that $a equals 1, $b equals 2, and $c equals 3)

1. The $a > $b part equates to true if the current value of $a is greater than the current value of  $b, otherwise it equates to false. In our example 1 ($a) isn't greater than 2 (b$) so this part would equate to false.

2. The $c part equates to true if the current value is considered Truthy, in the case of numbers this is any value other than 0 (zero), otherwise it equates to false. In our example 3 ($c) isn't equal to 0 (zero) so this part would equate to true.

3. The Boolean outcomes of each of the two parts are recombined to determine the overall outcome of the whole expression. The and operator equates to true if both it's left and right conditions equate to true, otherwase it equates to false. In our example the outcome of part 1 was false and the outcome of part 2 was true, so when the and operator is applied (eg. false and true) the overall outcome would be false.

The issue with each of your condition expressions is that the right side of each of the and operators will only equate to false if the referenced variable equals zero, and this isn't what you're trying to test for. Your conditional expressions should look as follows

(if: $a > $b and $a > $c)[(goto: "Ending A")]

(else-if: $b > $a and $b > $c)[(goto: "Ending B")]

(else-if: $c > $a and $c > $b)[(goto: "Ending C")]

 

by (2.5k points)
That will add 2 more points to the point it already had, you can change it to whatever you want. If you want it to add 1 more point like the first one, do + 1
by (2.5k points)
Opps, Grayelf is right. I tend to forget what makes sense to me doesn't always make sense to a computer.
by (210 points)
Thank you Glitchy and Grayelf!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...