0 votes
by (880 points)
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname">
Last name:<br>
<input type="text" name="lastname">
<input type="submit">

So this is what is used for users to write their names im assuming so how does it save the name ? The players name wil also need to be recalled back so im assuming it would be $playerName.

So hello $playerName and then it would spit out hello and then the players name?

also would i need to link it to players name or does it do that ?

How does it save what the person chooses if its a button press? like <<button  "Im red">><</button>>

would i need to make the player character as an array or an object?

1 Answer

0 votes
by (68.6k points)
selected by
Best answer

That is an HTML form, which you should not attempt to use in strory formats, at least not withou significant modification.


I'd suggest something like the following if you wanted the first/last names as separate entities:

''First name:''
<<textbox "$pcFirstName" "">>

''Last name:''
<<textbox "$pcLastName" "">>

Or, if you wanted the name as a single entity, something like:

<<textbox "$pcName" "">>

The <<textbox>> macro automatically stores the player input into the given variable name, you don't have to do anything else for it to work.


You may want to do some sanity checking on the value(s) to ensure the player hasn't done something silly like leaving the value blank/empty.  As an example of that:

''First name:''
<<textbox "$pcFirstName" "">>

''Last name:''
<<textbox "$pcLastName" "">>

<<button "Continue">>
	<<set $pcFirstName to $pcFirstName.trim()>>
	<<set $pcLastName  to $pcLastName.trim()>>

	<<if $pcFirstName is "">>
		<<replace "#input-error">>Please enter a first name.<</replace>>
	<<elseif $pcLastName is "">>
		<<replace "#input-error">>Please enter a last name.<</replace>>
		<<goto "Next Passage">>

And the style for the #input-error element: (goes in Story Stylesheet)

#input-error {
	color: red;
	margin-left: 2em;


SEE: <<textbox>>, <<button>>, <<goto>>, <String>.trim().

by (880 points)
edited by
Darn i dont know how to say it but, how do i have a "preset" name in the boxes that the user can use or just delete?

Or a button that makes random names?

Or just a way to make like the last name show up but is still editable but can be used by the player.
by (68.6k points)

If you'd read the documentation on <<textbox>> that I linked in my last reply, then you'd know that the second argument is used as the default value.  For example:

''First name:''
<<textbox "$pcFirstName" "John">>

''Last name:''
<<textbox "$pcLastName" "Doe">>