Inform: How do I get the player to input a name for themselves? The name keeps changing to whatever the player typed last!

+1 vote
276 views
asked Mar 26 in Authoring by mattweiner (121 points)
recategorized Mar 27 by Alex

In Inform 7, there is a way to get the player to input a name at the first prompt with code like this, but if you use this exact code in Inform 6L02 and later then the player's name will always appear as the last command typed.

the player name is some text that varies. 


To decide whether collecting names:
	if the command prompt is "What will your name be?  ", yes;
	 no.

When play begins:
	now the command prompt is "What will your name be?  ";
	
After reading a command when collecting names:
	now the player name is "[the player's command in title case]";	
	now the command prompt is "> ";
	move the player to the location;
	reject the player's command.

1 Answer

+3 votes
answered Mar 26 by mattweiner (121 points)

In Inform 6L02 and later versions, when you assign a variable or property to a string with a text substitution in it like "[the player's command]" then Inform by default views that as an instruction to evaluate that substitution anew every time. This lets us do things like set the description of a watch to include "[the time of day]" and have Inform automatically print out the time it is when we look at the watch.

In this case, this means that when we say

now the player name is "[the player's command in title case]"

Inform takes it that we will always want the player's name to be whatever "[the player's command in title case]" evaluates to at that moment. If the player has just typed "x me" Inform will evaluate the player name to me "X Me."

When we don't want that to happen, we use an operator called "the substituted form." This freezes the string to whatever text it inputs when evaluated right now, at the moment we're assigning it. So if we change that line to:

now the player name is the substituted form of "[the player's command in title case]"

then Inform will evaluate whatever the player's command just was (say, "biffalo buff"), put it in title case ("Biffalo Buff"), and then freeze the player name to be that exact text. So the player name will be "Biffalo Buff" forevermore (or until we change it again), as desired.

commented Mar 26 by Paul_Erdos (39 points)
I'm not really sure if this is a problem with my interpreter or with Inform, but in jzip, anyways, the text will not appear unless the 'in title case' is placed outside the quotes/brackets, as such:

now the player name is the substituted form of "[the player's command]" in title case;
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...