Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

I want to create a prompt box in which the answer becomes a correct or incorrect variable

$
0
0
Hi there, I'm using Harlowe on Twine 2.0

I've spent the entire day trying to figure out what is probably an easy piece of code. I have a passage in which I'd like the user to complete a basic maths task. They need to add three numbers together, and only when they give the correct answer can they proceed to the next passage.

There is important text on the passage that gives the user the info they need to complete the task. I then want them to click a button (send results) that opens a text box for them to input their answer. The correct answer is 71. If they give that answer, I then want a notification to replace the $results tag that says 'That looks correct. Please return to your [[homepage]].' And if they input ANY other answer (which is wrong), I want an additional piece of text that says 'Oops. That doesn't look right. Please try again.'

The problem is that a) if the user inputs the wrong answer, the $results hook is no longer click-able, so they can't retry. It just becomes plain text.

Even so, I cannot seem to find a way of showing an 'incorrect answer' reply without it ALWAYS being visible to the user.

This was my original code (which is probably very wrong):

(set: $total to "0")

[Send results]<results|

(click: ?results)[
(set: $total to (prompt: "Please enter the total below (see task for instruction)", "Enter total here") )
]

(live: 1s)[
(if: $total is "71")[
(replace: $results)[Task submitted. Please return to your [[homepage]].]
]
(else:)[
(replace: $results)[Oops. That doesn't look right. Please try again.]
]

The problem here is that $results is always something other than 71 until the user submits it as 71. So the incorrect message is always displayed. I tried setting $total to 71 at the start of the passage, but that bypasses the user having to input it (I can't explain how or why, it just... didn't work)

I then tried replacing the (else:) macro with

(if: $total is (range: 1,70) or (range: 70,1000))[Oops, that doesn't look right. Please try again.]

So a few things I need help with. Firstly, what am I doing wrong/missing out of the code; secondly, how can I get the prompt to appear as many times as needed; and thirdly, how do I display an incorrect total message that only appears if $total is not "71" AFTER the prompt box has been interacted with.

Thank you.

Viewing all articles
Browse latest Browse all 1844

Trending Articles