[Twine 2][Harlowe 3] Making user input

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.9
Story Format: Harlowe 3.1.0
I am trying to make game using Twine, and I have made a puzzle and I am hoping to make a simpler way to put in the solution other than putting all number from 111-999. I have looked about and nothing is working.

If I’m understanding correctly, you’re looking for a way for the player to directly input a solution/answer without needing to offer them a huge number of choices?

The easiest (but least elegant in most cases) way of doing things would be to use prompt

Eg:
(set: $name to (prompt: “Enter the code:”, “00000”))

The downside of prompt is that it doesn’t use the styling of the game, but defaults to the system colors.

Someone has figured out a workaround so that you could produce something less distracting (full disclosure, I haven’t tried this method - just tracked it down online).

I just tried prompt and it looks like it now inherits the styling from the story - so that’s a plus.

Here’s another link that might be useful on how to extend the functionality in Harlowe to handle other types of input – especially if you don’t want to use prompt.

1 Like

Perhaps you could also give the (cycling-link:) macro a look?

For example:

It's all up to you MacGruber. All you have to do is to unlock that 3 digit combination lock...

{
(cycling-link: bind _firstDigit, "1","2","3","4","5","6","7","8","9")
-
(cycling-link: bind _secondDigit, "1","2","3","4","5","6","7","8","9")
-
(cycling-link: bind _thirdDigit, "1","2","3","4","5","6","7","8","9")
}

{
(link:"I've got this; let's open the briefcase!")
[
(set: _combination to _firstDigit + _secondDigit + _thirdDigit)
(if: _combination is "911")[You've got it! How did you manage? [[Give Kristen a passionate kiss]].]
(else:)[Nope, that's not it... That thing is about to self-destruct; you're so screwed! [[Back to HQ]].]
]
}

As explained by others before me. Harlowe doesn’t include support for using standard HTML <input> elements within a Passage, so you need to use JavaScript to hack access to the internals of the story format’s engine components to add that support.

In the past you would need to do that JavaScript hacking yourself, these days you can use Chapel’s Unofficial Custom Macro Framework for Harlowe instead.

Using Chapel’s addon has an added advantage as it includes the code for a (textbox:) macro within its Example section.

1 Like