Cancel a prompt without leaving blank space?

0 votes
asked Jul 14 by Denny (180 points)

Twine 2.1.3, Harlowe 2.0.1:

So, I've got this code here:

(set: $name to (prompt: "What is your first name?", "Type your name here"))

Your name is $name.

[[Okay|okayName]]

But if the prompt is cancelled (say you change your mind) then I have a blank space where $name is, which is funny, but not what I want. I'd like to go to the previous passage. Can't figure that one out... Thanks.

1 Answer

+1 vote
answered Jul 14 by geekdragon (700 points)

Cancelling the prompt yields an empty string, so you can check for an empty string and return to the previous passage if necessary:

(set: $name to (prompt: "What is your first name?", "Type your name here"))
(if: $name is "")[(undo:)]

[[Okay|okayName]]

I prefer adding a dash of snark. This version assumes you've been to at least one previous passage, and the current passage is called "GetName". It reloads the prompt until they make an effort:

(if: (history:)'s last is "GetName")[
	(set: $name to (prompt: "No, REALLY. I need your first name.", "Type your name here. For real."))
](else:)[
	(set: $name to (prompt: "What is your first name?", "Type your name here"))
]
(if: $name is "" or "Type your name here")[(goto: "GetName")]

Your name is $name.

[[Okay|okayName]]

 

commented Jul 14 by Denny (180 points)

Thanks, geekdragon, that works well, and I wasn't aware of the "undo:" macro so I learned something new. Appreciate having the snarky option for possible future snarkiness.wink

...