I've been tying to work out how to give players the option to type their own name rather than just choose one from a selection. How can I do this?
I'm not settled in a format yet but I think I'll stick with T1 with Sugarcane / Sugarcube 2 at least for now.
Thanks in advance!
Comments
I've also added a file which is a basic example of the above.
'Your name is <textinput $name>>
with a link to the next passage containing '<<display $name>>' but it gives me the following error -
'<<display>>: "state.history[0].variables.mname == null && (state.history[0].variables.mname = 0);state.history[0].variables.mname" did not evaluate to a passage name'
You need to be careful which tags you assign to your questions because sugarcube 2 and sugarcane are two different story formats.
This is why you received the "no macro or passage called 'textbox'" error message because <<textbox>> is a SugarCube macro and it seems that you are actually using the Sugarcane story format.
The <<display>> macro is used to display the contents of passages and depending on the value of $name in your example you will get one of three results:
1. If the value of $name is the name of a passage then the contents of that passage will be displayed within the passage containing the <<display $name>> macro call.
2. If $name has a value but that value is not the name of a passage then you will receive the following error: <<display>>: The "a" passage does not exist
3. If $name has no value or its value is an empty String then you will receive an error similar to the one included in your post.
If you want to output the current value of a variable then you should be using the <<print>> macro.
I mean, we could guess, but that's hardly fair to us. There are various ways to do what I think you probably want. Rather than enumerate them all, however, it would be nice to be able to cut to the chase.
I decided to start a discussion topic with this in more depth, but it hasn't been approved yet, I think?
<<textbox "$name" "">>
<<if $name isnot "">>
<<goto "MainPassageInGame">>
<<endif>>
Basically what I wanted the code to do is you input the name in the textbox, and it'll go to the main passage to start the TWINE novel. BUT if the reader should happen to 'hit return' without typing in anything... I want them to put a name in, OR I can have it set to a 'default name' and move onto the Passage.
1. Create a passage named StoryInit if you don't already have one—that's a passage which has special meaning to SugarCube. Put something like the following in it, much as Claretta described: That will setup the default name.
2. Use something like the following where you want the name entry to be: That will inform the player that they need to enter a name if they empty the textbox or leave nothing but spaces.