[I7]Allowing player to choose their own name. (SOLVED)

I am fairly new to this (Inform is mostly a time filler for me) and so I am not very good at it.

I wanted to provide the player a chance to “name” themselves, something like this;

Something like that.

Thank you.

Taking in and storing direct player input will require the use of indexed text variables and usually the “after reading a command” rule. To get an idea of what that particular rule is like, look at Example 405 in the manual (Identity Theft).

The basic process is to make a very specific situation so that the “After reading a command” rule will fire off only at the desired moment(s). You can do this with variables, scenes, or really any combination of conditions. Inside of that rule, you write in the code that processes the player’s input and stores it into an indexed text variable.

Always make sure the rule finishes with “reject the player’s command” or you’ll get unwanted errors like “That’s not a verb I recognize.”

Here’s a quick write up of code that can produce what your example asked for:

[code]There is a thing called a red pill carried by player.
The red pill can be ready, eaten, or digested. The red pill is ready.

Instead of taking red pill:
say “You pop the red pill into your mouth, and awake in a liquid-filled vessel.[paragraph break]What is your name?”;
now red pill is eaten;
remove red pill from play.

Myname is an indexed text that varies.

After reading a command when red pill is eaten:
now Myname is the player’s command;
say “Hello, [Myname].”;
now red pill is digested;
reject the player’s command.[/code]
As you can see, the player’s input is taken as a name only when the pill has entered the “eaten” state, and then once it becomes “digested” the parser returns to normal operation.

A mischievous player may think to type in huge or unsavory names for fun. You can add to the “after reading a command” rule to refuse undesirable inputs. Chapter 19 of the manual is all about processing texts and will definitely help with that.

Let me know if you need more help getting it written for your specific needs.

Wow, thanks, that is exactly what I needed!

To me it feels weird that you can keep changing the state of the pill after it has been “removed from play”. But I suppose removing something from play just means it is taken off the map, so to speak - it does not mean the object is destroyed and memory reallocated, which you might expect if you’ve coded in… Well, pretty much any other language really.

A location is just a property of an object. You wouldn’t expect any language to destroy an object if you null one of its properties, right? (You must be thinking of an object’s memory address. I suppose it’s easy to associate the location in memory to the location in the game world.)

No, I’m not confusing memory locations with map locations.

It’s about the phrasing I think. I would expect something that sound more like the rest of I7 terminology - “now the location of the pill is nothing” or “now the pill is nowhere” or “move the pill off stage” or whatever. The phrase “remove the pill from play” sounds like it’s something else, like you’re saying “I’m done with this object, take it outside and grind it to bits”. IMHO.

You may want to take a look at this post and “Example 405 - Identity Theft” in The Inform 7 Documentation.

Hope this helps.

“now the pill is off-stage” works.

I know I’m a bit late to the party here, but I had to hash out how this worked in my current WIP, so I can’t resist putting my two cents in.

The code posted above will get you, as it were, a single-use name with no limitations on what the player can type in, but I wanted the game to store the name, to be able to refer to the player by their first, last, or full name, and to reject inappropriate inputs. Here’s the snippet of code I used to do that (which will run by itself, though it won’t be very fascinating).

[code]There is a room called Choose Your Name. “Type in a first and last name.”

The player’s forename is an indexed text that varies. The player’s full name is an indexed text that varies. The player’s surname is an indexed text that varies.

To decide whether collecting names:
if the player is in Choose Your Name, yes;
no.

After reading a command when collecting names:
if the number of words in the player’s command is greater than 2:
say “[line break]You’re a Space Marine. You keep it simple. You only need two names.”;
reject the player’s command;
if the number of words in the player’s command is 1:
say “[line break]You’re a Space Marine, not a pop star. Two names, soldier: first and last.”;
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 player’s surname is word number 2 in the player’s full name;
say “Welcome aboard, Commander [player’s surname]!”;
say “[banner text]”;
move the player to Lower Deck Corridor;
reject the player’s command.

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

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

The Lower Deck Corridor is a room. “This is a hallway on the lower deck of the ship.”
[/code]

Calm does this rather nicely.

Sorry to interweave this thread with the bits about removing from play, but for completeness: it looks like “move the pill off-stage” does not in fact work, but “now the pill is off-stage” does.

the demo is a room.

a springy thing is a thing in the demo. 

before doing something to the the springy thing:
	say "Before you know it, the thing bounces off and is gone.";
	now the springy thing is off-stage;
	stop the action.
	
The register is a thing. The description is "The Book of Everything lists [the list of on-stage things]". The player is carrying the register.
		
definition: a thing (called item) is on-stage:
	if the location of the item is not nothing, yes;
	no.
	
test me with "x register / take thing / x register";

“on-stage” is my own definition here - is there already some other way of excluding things that are “removed from play” from iterations like these?

I thought “on-stage” was already defined in the standard library.

It is.

The standard definition is not quite what’s quoted above. I7 considers an object on-stage if it is indirectly contained (enclosed by) a room.

(So if a container is off-stage, its contents are also off-stage.)