Trying to create random names using text.

Still working on the same game from my last thread. I’ve created a “secret police” type of person that has a random codename assigned at the start of a game.

When play begins: repeat with op running through all people who are Secret Police: now the codename of the op is "[one of]Alpha[or]Bravo[or]Charlie[or]Delta[or]Echo[or]Foxtrot[at random]-[a random number between 200 and 999]".

I want to be able to have the game understand this codename as meaning this person, but I cannot figure out how to have the game treat this codename as the given name of the person. I can use a “When printing the name of…” rule, but that doesn’t mean typing “charlie-452” will make the game know I want the person codenamed “Charlie-452.” There will be so many of these people that I cannot practically name them individually.

I would do this by making the two parts of the codename separate properties.

A person can be secret police. 

A phonetic is a kind of value. The phonetics are Alpha, Bravo, Charlie, Delta, Echo and Foxtrot. Every person has a phonetic. Understand the phonetic property as describing a person when the item described is secret police.

Every person has a number called the numeric. Understand the numeric property as describing a person when the item described is secret police.

To say the codename of (X - a secret police person):
	say "[Phonetic]-[numeric]".

Rule for printing the name of a secret police person (called the subject):
		say "[the codename of the subject]".

When play begins:
	repeat with X running through secret police people:
		now the phonetic of X is a random phonetic;
		now the numeric of X is a random number between 100 and 999.
		
After reading a command:
	let T be "[the player's command]";
	replace the regular expression "-" in T with " ";
	change the text of the player's command to T.

This will accept “Alpha” and “287” as synonyms for Alpha-287, but that seems harmless.

You might want to make A,B,C,D,E,F shorthand for the phonetic parts.

Understand "A" as Alpha. Understand "B" as Bravo. Understand "C" as Charlie. Understand "D" as Delta. Understand "E" as Echo. Understand "F" as Foxtrot.

Does the player mean doing something other than going with a direction: it is unlikely.

The last line is there to prevent atrocities such as “What do you mean, the down, Delta-157 or Delta-801?”

If secret police are a kind of person, you can also just “Understand the codename property as describing secret police”. This won’t let you use the pieces individually, but your original example will work.

Also you probably want to set the codename to the substituted form of that text, so it doesn’t change in play.

I ended up using a combination of your two methods. I started with Draconis’ suggestion, then added another text property that’s only the last number which is also understood as that person, so you can just say “look 893” and get the description of Delta 893. The code snippet I gave now looks like:

When play begins: repeat with op running through all people who are Secret Police: let id be a random number between 200 and 999; now the identifier of the op is "[id]"; now the codename of the op is the substituted form of "[one of]Alpha[or]Bravo[or]Charlie[or]Delta[or]Echo[or]Foxtrot[at random] [id]".
This is almost completely working, but the interpreter seems to insist on adding “a” or “an” in front of the codenames, which looks weird. The printout of what’s in a room will always say “a Delta 893 and an Alpha 339.” The code I used for name printing is dirt simple:

Rule for printing the name of a Secret Police: say "[codename]".
Could this be improved to remove the extra article?

I think it works if you declare the op proper-named when you assign its codename:

When play begins: repeat with op running through all people who are Secret Police: let id be a random number between 200 and 999; now the identifier of the op is "[id]"; now the codename of the op is the substituted form of "[one of]Alpha[or]Bravo[or]Charlie[or]Delta[or]Echo[or]Foxtrot[at random] [id]"; now the op is proper-named.

That doesn’t seem to work. It compiles but has no apparent effect.

Edit: deleted rubbish.

How are you creating your secret police people in your code? Could you give us a minimal piece of compilable code showing the problem? Matt w’s suggestion works for me. (An alternative would be to give your secret police proper names in your code, e.g. “Fred is a secret police person.”)

I guess the obvious mistake on my end is I didn’t give any of the agents a name, I just said, for instance, “Lorraine & Stockton contains a Secret Police and a Secret Police.” It would be helpful if I could automatically assign all Secret Police a single name so that the articles disappear. I’d rather not have to give these people names every time they are created in my code, because all of them in the game will behave roughly the same way, like using weapons on targets that have certain properties, patrolling randomly, etc. Giving these people names other than the codenames is a problem because whatever I enter might interfere if the player types it. It’s also, well, extra typing I have to do.

Have you made secret police a kind of person then? If so, you could try adding “A secret police is proper-named” to the code. Though I’m still puzzled why matt w’s suggestion isn’t working for you.