0 votes
by (120 points)
Hello everyone, I am pretty new to Twine here. I use twine 2.2.1 harlowe. I want to make a multiple choice systems in twine which give out scores on each correct answers and finally give different results.

Something like that

1. This is question

(a) answer 1 (+5 pts)

(b) answer 2 (+0 pts)

(c) answer 3 (+ 0pts)

2.This is question

(a) answer 1 (+5 pts)

(b) answer 2 (+0 pts)

(c) answer 3 (+ 0pts)

I tried using like that

(if: $point1 is "")[
    |point1>[
        (link: "Answer 1")[
            (set: $point1 to "Answer 1")
            (set: $pa += 5)
            (replace: ?point1)[$point1]
            (display: "Check Selections")
        ]
        (link: "Answer 2")[
            (set: $point1 to "Answer 2")
            (set: $pa -= 0)
            (replace: ?point1)[$point1]
            (display: "Check Selections")
        ]
    ]
](else:)[$point1]

I also set check selections passage to check the selections

In check selections passage, I use like that

(if: $point1 !== "" and $point2 !== "" and $point3 !== "" and $point4 !== "")[
    (if: $pa > 15)[
        (replace: ?result)[Your english is very advanced! Excellent]
    ]
    (else:)[
        (replace: ?result)[Your english is non-existent! Work harder!]
    ]
]

This method is working. But I want to show different results based on different scores they get and I am now unable to do that due to limitations in that code. What I desire is like

if 20>$pa>15, (replace: ?result)[Your english is very advanced! Excellent!

if 15>$pa>5, (replace: ?result) Good, but work harder

if $pa<5, your level is bad

something like that. But I cannot show more than two outcomes in this test. If anybody could help me solve this problem, I would be very appreciated

1 Answer

0 votes
by (159k points)

Please use the Insert Code Snippet button in the above toolbar when adding a code example.

1. You can use a (if:) macro combined with one or more (else-if:) macros to check if one of a series of conditions are true.

(if: $score >= 15)[Score is in the High band]
(else-if: $score >= 10)[Score is in the medium band]
(else-if: $score >= 5)[Score is in the low band]
(else-if: $score < 5)[Score is too low to rate]


2. You can use the and & or operators to join multiple conditions together to form a larger one.
The following example uses the and operator to produce the same outcome as the point 1 exampe

(if: $score >= 15)[Score is in the High band]
(else-if: $score < 15 and $score >= 10)[Score is in the medium band]
(else-if: $score < 10 and $score >= 5)[Score is in the low band]
(else-if: $score < 5)[Score is too low to rate]


3. When using a (if:) + (else-if:) structure like those in points 1 & 2 you can often replace the last / final (else-if:) macro with an (else:) macro.
Doing this can be a good ideal because that (else:) will also handle any conditions your logic has missed.
The following example uses the (else:) macro to produce the same outcome as the point 1 & 2 exampes

(if: $score >= 15)[Score is in the High band]
(else-if: $score >= 10)[Score is in the medium band]
(else-if: $score >= 5)[Score is in the low band]
(else:)[Score is too low to rate]

 

The following is a modified version of your example, it handles the extra $pa related ranges as well as the situation where $pa is outside the stated range.

(if: $point1 !== "" and $point2 !== "" and $point3 !== "" and $point4 !== "")[
	(if: $pa >= 20)[
		(replace: ?result)[Score is outside allowed range, please report this error.]
	]
    (else-if: $pa >= 15)[
        (replace: ?result)[Your english is very advanced! Excellent]
    ]
	(else-if: $pa >= 5)[
		(replace: ?result)[Good, but work harder]
	]
    (else:)[
		(replace: ?result)[your level is bad]
    ]
]

 

...