Login
Remember
IF Answers
Ask a Question

# 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.

- inform7
- substituted-form
- players-command
- text

## 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;
asked Mar 26 in Authoring by Paul_Erdos (39 points)
edited Mar 30 by Paul_Erdos How do I organize events / sets of actions to execute when play begins?

## Related questions

- How to get rid of a rule that's blocking what I want the player to do? (Inform 7)
- How do I find the default parser verbs in Inform?
- Inform: How do I find the word count for text the player can read?
- How can I change the interface to look like Beyond Zork?
- Changing the subject of a verb

...