User input with links macro

Twine Version: 2.3.5
Story Format: SugarCube 2.30

Just trying to learn Twine so this might be stupid simple, but I was messing with textbox for user input (something as simple as “What’s your name?”) but noticed the latest documentation says it’s been deprecated and the link macro should be used. Simple enough, but I can’t figure out how to use the link function for user input. Any help is appreciated.

Because you didn’t use the toolbar’s Preformatted Text option to including your <<macro>> references we see them as <> in the question, which makes it difficult to know which macros you were asking about.

When posting code, please use the preformatted text option (</>) on the editor bar, otherwise it may come out mangled—as the macros in your (original) post did.

The only interactive macro that’s been deprecated is <<click>> and that has nothing to do with text input, so I have no idea what you mean—and since we cannot currently see what macros you attempted to refer to….

Regardless. There are two text input macros in SugarCube, neither being deprecated, <<textarea>> and <<textbox>>. The latter, <<textbox>>, is probably what you want.

Examples

Basic example:

What's your name?  <<textbox "$name" "">>

And printing its value on the next passage:

Ah.  Hello, $name, good to meet you.

Validation example, to ensure that the player inputs something:

What's your name?  <<textbox "_name" "">>  <<button "Continue">>
	/* Empty the error display. */
	<<replace "#name-error">><</replace>>

	/* Trim leading/trailing whitespace from the name. */
	<<set _name to _name.trim()>>

	/* Check if the name is empty. */
	<<if _name is "">>
		/* If so, show the player an error. */
		<<replace "#name-error">>You must input a name!<</replace>>
	<<else>>
		/* Else, assign it to a story variable and go to the next passage. */
		<<set $name to _name>>
		<<goto "Some Passage">>
	<</if>>
<</button>> @@#name-error;@@
1 Like

Ha. Oops.

Thank you. And you are right–now that I go back and look again, I realize it was totally my mistake: I was skipping right from the textbox macro to the “deprecated” text right below it … but totally skipping over the click mention. (TL;DR I should read more carefully.)