0 votes
asked ago 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
answered ago by (114k 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>>


commented ago 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!
commented ago 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)

commented ago by (114k points)
If this answer solved your 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.
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.