Input player's name?

Hi. I’m trying to make a game where you can give any name for your character. I 'd like to input the name and that name gets stored in a variable for later use. Storing inputs in variables is really basic in programming, but in Inform7, it seems to be a lot harder. I don’t know if there is an easy way to do that, and if there is, it will be really helpful a simple example. Thanks in advance.

The “Identity Theft” example here is a good start:

I did it, I copied the code and tried it, but it didn’t work as I espected. It seems that the code doesn’t work so well with the Hybrid Choices Extension (which I’m using too) and a scene just after input the name.

Make sure you are in parser mode and not CYOA mode when you want the player to type something in. I had a little trouble getting HC to switch into choice mode immediately after collecting the player’s name, but it works after the player LOOKs manually. You could prompt the player to do so after the banner text. (This may just be a glitch in my installation because sometimes I don’t get an automatic look upon starting a game, YMMV. I also had an issue with naming an object “letter” so I changed it, but didn’t bother figuring out why.) Here’s what I did:

[rant=hidden for space][code] “Identity Theft”

Include Hybrid Choices by Aw Freyr.

The player’s forename is a text that varies. The player’s full name is a 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;

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]”;
reject the player’s command;

Instead of looking for the second time:
switch to cyoa at Welcome-page.

[We also want to postpone the proper beginning of the game until we’ve gotten the name:]

Your Bedroom is a room. The printed name of Your Bedroom is “[if collecting names][otherwise][player’s forename]'s Bedroom[end if]”.

A missive is a thing. It is carried by the player. The description of the missive is “Dear [player’s full name], [paragraph break]You have won the Norwegian Daily Lottery! …”. Understand “letter” as missive.

Welcome-page is a page. “Welcome to your room! Wow, your room is pretty untidy. You’ve received a missive, it seems.”

readit is a page. “Curious, this missive. It’s actually a letter, you’re not sure why you use such extravagant terms as ‘missive’…”. It is for Welcome-page. It is a dead-end. The cdesc is “Read the letter…ahem…the missive.”

A choice-switch rule for readit:
unless the player carries the missive:
rule fails.

A page-toggle rule for readit:
try examining the missive.

dontread is a page. “Okay, let’s save that letter (okay…missive) for later.”. It is for Welcome-page. It is an end-page. The cdesc is “To the devil with this missive, you’ve got adventuring to do!”.

Rule for printing the banner text when collecting names: do nothing.

Rule for constructing the status line when collecting names: do nothing.



I believe you could technically use the page-output rules and run all of that example code there (actually “on” a page). I think that’s what they are for, but I haven’t used page-output extensively enough and would need to test further - I have gotten page-output to work successfully using an “if the player consents” yes/no within a page…so that may be the way to go.