Cancel a prompt without leaving blank space?

0 votes
asked Jul 14, 2017 by Denny (230 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.


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, 2017 by geekdragon (1,620 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:)]


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."))
	(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.



commented Jul 14, 2017 by Denny (230 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

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.