0 votes
asked by (620 points)
This is the idea:

$Name is the name of the player.

in the game, the named variable, or $name can be set to the player name.

The idea is, if you get a game over, a set name can not be used anymore and will display that the 'player is not available.


So, say the $Name is 'Adam". If you die in this game, $name's with "Adam" will be rejected for use.


is there a code that can make this happen?

1 Answer

+1 vote
answered by (60.6k points)

Assuming you want this to persist over multiple playthroughs, try something like the following.

First.  Place the following in your StoryInit special passage:

<<if ndef $usedNames>>
	<<set $usedNames to []>>

Next.  In the passage that allows the player to choose a name do something like the following:

<<textbox "_name" "">> \
<<button "Continue">>
	<<replace "#error-name">><</replace>>
	<<set _name to _name.trim()>>
	<<if _name is "">>
		<<replace "#error-name">>Please specify a name.<</replace>>
	<<elseif $usedNames.includes(_name.toLowerCase())>>
		<<replace "#error-name">>_name is not available.<</replace>>
		<<set $Name to _name>>
		<<goto "Next Passage">>

Finally.  In any passage where the player character dies do something like the following:

<<run $usedNames.pushUnique($Name.toLowerCase())>>
<<remember $usedNames>>


NOTE: The above code forces names to lower case for both the includes test and the list of used names.  If you wish case to matter, then simply remove both instances of .toLowerCase().


Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.