I’m using Twine 2.5.1 and SugarCube 2.36.1
I’m trying to translate from Harlowe to SugarCube (which is new for me) and finding it a bit of a mystery. So even the easy things I’m having trouble figuring out. For example, I have a pop up alert to have the player enter a character name
(set:$name to (prompt:"Enter your name: ", “default txt”))
I presume I’m meant to somehow use the UI.alert macro in SugarCube as an alternative to prompt? but how do I nest this inside the set statement?
thanks in advance
You want the
<<textbox>> macro. For example:
Enter your name: <<textbox "$name" "John Doe">>
EDIT, PS: You may want to look at the Harlowe to SugarCube guide within SugarCube’s documentation for help transitioning.
Thanks! Appreciate the links as well.
Actually in trying to implement this I’m still confused.
so would it look something like this?
<<set $name to <<textbox “$name” “John Doe”>> Enter your name>>
<label>Enter your name? <<textbox "$name" "John Doe">></label>
or something along these lines (which I realise don’t work),
Dialog.setup(“Enter your name:”);
Dialog.wiki(<<textbox “$name” “John Doe”>>);
I gave you a working example, based on your old† Harlowe example. Both the
<<textbox>> documentation and the Harlowe to SugarCube guide have working examples.
Did you not try any of them for some reason? If you did try them, did you encounter problems? If so, what were they?
† I say old example above because even Harlowe has a macro similar to
<<textbox>> now, named
(input:), with similar usage. Using
(prompt:) is no longer recommended.
Let’s go over your counter examples.
That won’t work. SugarCube macros are essentially statements, rather than expressions. Meaning they don’t yield/return values that you can assign to variables. You cannot pass them as arguments to other macros. Et cetera.
That would work—though I’m unsure why you’ve turned the instructional label into an interrogative, it’s a command not a question.
Anyway. The main difference from my example is wrapping the whole thing within an HTML
<label> tag, which makes the instruction,
Enter your name?, clickable to focus the input. That’s good for accessibility and definitely recommend practice, but not necessary just to get the text input.
That won’t work for a couple reasons:
<<script>> macro—not to be confused with the HTML
- You’re missing quotes around what you’re attempting to wikify.
You may also be using typographic quotes—i.e., curly quotes—which are not legal syntax. I say may because it could be that the forums changed them and you were using regular quotes in actuality.
Beyond those issues, I don’t recommend using a dialog simply to get input from the player.
@TheMadExile Yes, getting use to “SugarCube macros are essentially statements, rather than expressions. Meaning they don’t yield/return values that you can assign to variables. You cannot pass them as arguments to other macros” is one of the hardest transitions - just in terms of my logic planning.
The reason I thought of the use of is because I’m trying to find the Sugarcube macro that will allow me to have a pop-up dialogue box, not just a text box within the passage. As I said, I’m a novice with Sugarcube so still finding my way around. Obviously this didn’t do what I wanted, so my search goes on.
If you’re bound to try putting a
<<textbox>> in a dialog, the following should give you a starting point:
Dialog.wiki('<label>Enter your name:<br><<textbox "$name" "John Doe">></label>');