Combing Prompt and Live to make a timed prompt

Using Twine in Harlowe.

I’m trying to make a hacking game where players are prompted to enter a string of text on the screen accurately within a specific period of real world time. (basically a ticking countdown till you lose the game)

I have code that works for both the prompt and the timer, but the timer is not taking effect until the prompt is entered. Is there a way to do this so that the timer function will be on going while the prompt is on the screen?

Here is the code I have so far (want to get it working before I start adding random seeds for the player to type)

(set: $timer to 10)
(live: 1s)[
(if: $timer is 0)[
(goto: “Locked Down”)
(else: )[
(set: $timer to it - 1)
Security lock down in $timer seconds

(link: “start hacking.”)[(set: $name to (prompt: “Enter Command”, “”))
(set: $command to “Hack thing.”)
(if: $name is “Hack thing.”)(goto: “Good job you hacked it.”)[(set: $name to (prompt: “Incorrect Command. Enter Command”, “”))(if: $name is “Hack thing.”)[(goto: “Good job you hacked it.”)] ] ]

Thanks for any help.

As long as the (prompt:) dialog is up, other macros can’t run, so that’s why your timer isn’t counting down til it’s closed:

When the dialog is on-screen, the entire game is essentially “paused” - until it is dismissed, no further computations are performed, links can’t be clicked, and (live:) and (event:) macros shouldn’t fire.

If you switch the prompt out for a text input box it should work.


Is there a way to read from the text in that box or print it to other areas?

I wanted to make a command that at a certain timer number (say 1) checks to see if the right text has been entered into the text input box, but there isn’t an “enter” like on (input:) So basically I don’t know where to tell that command to target. Is that possible with a text input box? My initial read though suggest the answer is no, but I am still new to this.

Sorry, I’m so used to using text input boxes for this kind of thing that I forgot that it’s not really obvious how to do it. You need to create your own “enter” button for it. It will look something like this:

(link: "Start hacking.") [(input-box: bind $name, "=X=", 1)
(link-repeat: "Enter")[(if: $name is "Hack thing.")[(goto: "Good job you hacked it.")](else: )[(dialog: "Incorrect Command.", "OK")]]]

That gives you a text input box where the value of the variable $name is set to whatever the player types into the box, and a reusable link that says “Enter” that, when clicked, will check what the value of $name is and act accordingly.

1 Like