Keeping text from appearing until a text box is filled

So I’ve just started learning twine, using the sugarcube format, and I’ve run into a roadblock that I’ve spent the last several hours looking for a solution for. Maybe I’m missing something obvious, maybe not, but hopefully you guys have a solution. Basically I’m just trying to keep the next line of text from appearing until after the user/player inputs their name. Here’s the code:

<<fadein 20s 5s>> What is your name? <<textbox "$name" "">> <</fadein>>

<<if textbox $name>>
<<set $name true>>

<<if $name is true>>
<<fadein 25s 5s>> What are you carrying with you, <<print $name>>?
[A snack]
[A meal]
[Walking stick]
[A water bottle]
[Extra clothes]<</fadein>>

Let me know if you need more context. I want to play around with an inventory system soon, hence the list of items for the player to select from, but later, this problem first lol.


It’s not really possible without the use of some custom macro.
You could instead of having the next text appearing below, move the player to another passage (that way you don’t need to worry about it :stuck_out_tongue:


<<if textbox $name>> [should be <<if $name>> or <<if def $name>>]
<<set $name true>>

You would be overriding the player’s input by changing the value of $name from that input into the value true.

If you want to go the custom macro route, you might want to look at Maliface’s <<listen>> macro

1 Like

The problem is this: how do you know when the player has entered their name? The game can be made to execute code when the player starts typing, but it can’t possibly know when they’re finished without giving them a way to signal that they’re done. How do you plan to do that?

You could, for example, give them a link to click to confirm their name:

<span id="continue">
  <<link "Confirm">>
    <<if $name>>
      <<replace "#continue">>
        /* Your code here */

Or you could use the macro Manon linked above to execute the code once the player presses enter:

  <<textbox "$name" "">>
<<when 'keypress'>>
  <<if _event.code === 'Enter' and $name>>
    <<replace "#continue">>
      /* Your code here */

<span id="continue"></span>

Edit: another thing you should keep in mind is that as long as your textbox is onscreen, the player will be able to change the name even after the new text has appeared. To prevent that, you can use a temporary variable in the textbox, like this:

<<textbox "_temp_name" "">>

And then at the beginning of the code you run after the name is selected:

<<set $name = _temp_name>>

Or, you know, just move the player to a new passage. That would be the simplest solution.


That was super helpful thank you so much! And you’re right, just moving the item selection to the next passage would be the simplest thing to do. Thank you and thank you @Manon for the macro, that made things a lot easier and probably make other things easier too!

1 Like