0 votes
by (120 points)
I'm trying to create a multiple choice quiz (Sugarcube - Twine2). The final result should corrispond to the answer that the player gives more times. (Meaning: if the player answers 8/10 "B" the final result is B profile)

Many Thanks!




1 Answer

0 votes
by (159k points)

It is unclear from your question whether or not you want to track the actual selection for each of the 10 question as well as the selection counts, or just the selection counts. You also didn't state what the rating scale was.

I will assume you only want the counts and that the rating scale is A to E. (a 5 choice scale)

1. Initialise the variable to store the counts within your project's StoryInit special passage.

<<set $counts to {
	"A": 0,
	"B": 0,
	"C": 0,
	"D": 0,
	"E": 0

2. Ask the 1st queston and increment correct count based on the selection made.

Question 1: Blah blah blah

<<link "A" "Question 2">><<set $counts["A"] += 1>><</link>>
<<link "B" "Question 2">><<set $counts["B"] += 1>><</link>>
<<link "C" "Question 2">><<set $counts["C"] += 1>><</link>>
<<link "D" "Question 2">><<set $counts["D"] += 1>><</link>>
<<link "E" "Question 2">><<set $counts["E"] += 1>><</link>>

2. The code for questions 2 to 9 will look similar to the above except you would change the Target Passage ("Question 2") argument of the <<link>> to "Question 3", "Question 4", and so on.

3. The code for question 10 will look similar to the above except you will change the Target Passage argument of the <<link>> to something like "Results".

4. The Results passage.

This is where you place the logic to calculate what the maximum count was and which choices have that count, you will note that I used the plural because there could be more than a single choice that has the same count as the maximum.

	/* Determine the maximum count and the choice(s) that equal it. */
	<<set _maxCount to 0>>
	<<set _maxChoices to []>>
	<<for _choice, _count range $counts>>
		<<if _count gt _maxCount>>
			<<set _maxCount to _count>>
			<<set _maxChoices to [_choice]>>

		<<elseif _count is _maxCount>>
			<<set _maxChoices.push(_choice)>>

\Result was _maxCount/10 for <<nobr>>
	<<if _maxChoices.length gt 1>>
		<<= _maxChoices.join(" and ") >>

\<<if _maxChoices.includes("A")>><br>Profile A<</if>>
\<<if _maxChoices.includes("B")>><br>Profile B<</if>>
\<<if _maxChoices.includes("C")>><br>Profile C<</if>>
\<<if _maxChoices.includes("D")>><br>Profile D<</if>>
\<<if _maxChoices.includes("E")>><br>Profile E<</if>>


by (120 points)
Thank you so much!

This looks exactly what i was looking for.

I'm going to try it right now!

Thank you!
by (120 points)
It works! Thanks for your time!

Now i'm trying to assign different value to each answers (meaning: if you choose "A", you recive 2 points. If you choose "B", you recive 3 points). Each prifile should corrispond to a range of value (meaning: profile "A" from 0 to 10; profile "B" from 11 to 15)

by (159k points)
edited by

If this answer solved your original issue could you use the relavent button to mark it as such, that way the Question Title of this question will change from Blue to Green which lets others know there is an acceptable answer.

by (159k points)

Sorry that I missed the fact you asked a further question related to 'points', this site's software doesn't make it easy to track replies made by the original poster of a Question. This is one of the reasons why we recomend people create a new Question instead of adding more questions to the end of an existing Question.

The solution to your new qestion is similar to that of your original.

1. Initialise a variable to store the total number of points allowcated.

This is done in your project's StoryInit special passage.

<<set $points to 0>>

2. Increase the total number of points each time a selection is made.

Question 1: Blah blah blah

<<link "A" "Question 2">><<set $points += 2>><</link>>
<<link "B" "Question 2">><<set $points += 3>><</link>>
<<link "C" "Question 2">><<set $points += 4>><</link>>
<<link "D" "Question 2">><<set $points += 5>><</link>>
<<link "E" "Question 2">><<set $points += 6>><</link>>

3. Determine which profile to show in the Results passage.

You can use the <<if>> macro and the related <<elseif>> macro to test the current value of the $points story variable.

<<if $points gte 0 and $points lte 10>>
	Profile A
<<elseif $points gte 11 and $points lte 15>>
	Profile B
<<elseif $points gte 16 and $points lte 20>>
	Profile C
<<elseif $points gte 21 and $points lte 25>>
	Profile D
<<elseif $points gte 26 and $points lte 30>>
	Profile E
	ERROR: The total number of points is outside the expected range, please contact the Developer.