5.2. Traits Determined By the Player

| Chapter 5: The Viewpoint Character |

| 5.2. Traits Determined By the Player

Some IF tries to make the viewpoint character more congenial to the player by allowing some customization.

Identity Theft demonstrates asking the player to supply the viewpoint character's name.

Pink or Blue demonstrates a way to let the player choose a gender at the start of play: this will mostly be interesting if the rest of the game makes some use of the player's choice. Since that example is written expressly to demonstrate included Inform 6 code, however, we may find it more congenial to generalize from the more flexible Baritone, Bass.

This is not the only way to go - as we'll see in the next section, there's also something to be said for making the viewpoint character a strongly distinct creature with well-defined preferences and attitudes.

405
| Example Identity Theft Allowing the player to enter a name to be used for the player character during the game. |
WI

Let's say we want to allow the player to enter any name he likes for his character. Moreover, we want to reject very long names (which are likely to be mistakes anyway), and we want to extract the player's chosen first name from the rest. "Identity Theft" The player's forename is an indexed text that varies. The player's full name is an indexed text that varies. When play begins: now the command prompt is "What is your name? > ". To decide whether collecting names: if the command prompt is "What is your name? > ", yes; no. After reading a command when collecting names: if the number of words in the player's command is greater than 5: say "[paragraph break]Who are you, a member of the British royal family? No one has that many names. Let's try this again."; reject the player's command; now the player's full name is the player's command; now the player's forename is word number 1 in the player's command; now the command prompt is ">"; say "Hi, [player's forename]![paragraph break]"; say "[banner text]"; move the player to the location; reject the player's command. We also want to postpone the proper beginning of the game until we've gotten the name: Instead of looking when collecting names: do nothing. Rule for printing the banner text when collecting names: do nothing. Rule for constructing the status line when collecting names: do nothing. Your Bedroom is a room. The printed name of Your Bedroom is "[player's forename]'s Bedroom". The player carries a letter. The description of the letter is "Dear [player's full name], [paragraph break]You have won the Norwegian Daily Lottery! ...". If we are compiling for Glulx, this is enough to capture not only the player's name but also the capitalization he uses. If we are compiling for the Z-machine, the player's input will unfortunately be reduced to lower case before we can inspect it. If we would like by default to capitalize the first letter of each word of the name, we might substitute the following after reading a command rule: After reading a command when collecting names: if the number of words in the player's command is greater than 5: say "[paragraph break]Who are you, a member of the British royal family? No one has that many names. Let's try this again."; reject the player's command; now the player's full name is "[the player's command in title case]"; now the player's forename is word number 1 in the player's full name; now the command prompt is ">"; say "Hi, [player's forename]![paragraph break]"; say "[banner text]"; move the player to the location; reject the player's command.

441
| Example Pink or Blue Asking the player to select a gender to begin play. |
WI

298
| Example Baritone, Bass Letting the player pick a gender (or perhaps other characteristics) before starting play. |
WI

Previous | Contents | Next