0 votes
by (220 points)
Apologies if it's a dumb question but i just started using twine today, and i can't seem to figure it out.

i'm using sugarcube, and i want to have the player input a name for a variable(which works fine with the textbox thing) and then immediately print out what they just put in.

unfortunately the print command prints the default name for the variable even before you write anything inside the textbox.right now it looks something like this :

name the variable? <<textbox "$variable" "default">>

<<print $"variable">>


is there a way to make both of these work right after each other in the same passage?

2 Answers

+1 vote
by (1.1k points)

You need to make the variable appear after it's set, the easiest option for you may be to use replace. 

<<textbox "$name" "name here">>
<<button "Accept Name">><<replace "#nameAppear">>Welcome $name<</replace>><</button>>

<span id="nameAppear">Welcome</span>


by (220 points)
thanks m8, works like a charm!(and i even understood why...i think)

much appreciated
by (1.1k points)
Np, basically you've got a <span> which has an id of "nameAppear" which you can replace the contents of by using <<replace "#nameAppear">> <</replace>> which replaces what's in the span with whatever is between <<replace>> and <</replace>> so you're printing out "Welcome" first of all, and then replacing the "Welcome" with "Welcome $Name" which prints out the changed variable which is altered using <<textbox>>


If you want the text box to disappear, you can also replace it with nothing (or something) by creating a span around it, and then using replace.
+1 vote
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using. Using them instead of including that information in the question's text makes it easy to see, and easier for others to search for.

by (220 points)
i shall certainly do so