Linking to a sticky random string..... so to speak

Hello again -

Could somebody point me in the direction so I can learn how I link to a answer revealed elsewhere in the game.
ie the player discovers a list of names, and “one name sticks out. Mr Biggins” (or whatever) I’ve generated the code for that to happen all fine and dandy. But I want the name to change.

is there a way to attribute the option chosen in any one particular game to be used later on.

-this links in with my previous posts about the player needing a name to get a table reservation, I now have the two bits just need to link it all together.

Thanks

You can “link to” text with a “to say” phrase. Here’s an example using sticky random:

To say villain's name: say "[one of]Jim[or]Henry[or]Sally[sticky random]".

The description of the list of names is "One name stands out: [villain's name]."

ahhh splendid! Thats interesting. Thanks.

Ahhh gawsh everyone on here is so helpful! I was wondering if people would get all snippy but they have been so super nice. Thanks!

Hmmmm - almost got it.

However I don’t think it’s understanding the token when I compile.

Problem. I was unable to understand what you meant by the grammar token ‘pax’ in the sentence ‘if the player’s command matches “[pax]” begin’

To say pax name: say "[one of]Mr Biggins[or]Mr Trampton[or]Mr Smith[sticky random]".

Instead of examining the document, say "One name stands out: [pax name].".

After reading a command when the command prompt is "Wonderful, what name is the reservation under sir? >":
	if the player's command matches "[pax]": 
		say "Yes sir, please come this way. I believe we have a booth for you.";
		move the player to the booth;
		now the command prompt is ">";
		reject the player's command;
	otherwise:
		say "Oh no, I don't have anything under that name.";
		now the command prompt is ">";
		reject the player's command.

This is all the code that relates to this bit, but i’ve chopped a bit out relating to the '…after reading a command when the commnd prompt is…" as that is just going to be be too much for the post.

I’m thinking that maybe I need to select the pax name when play beings or something…

Thanks

I think the problem is that tove’s solution gives you a text substitution, which is fine if you just need to keep printing it out (or understanding it even), but matching a bit of the player’s command requires a snippet or text or indexed text (I have trouble keeping them straight). Setting the string when play begins is probably a good way to do it.

Oh, yeah, that’s what I get for dashing off an answer without fully understanding your question. Text substitutions, including “to say” phrases, are great for output text; not so much for input. I also have trouble keeping the various text options in Inform straight, but I think you could do it with a table. So, say you have a table with roles (murderer, herring, accomplice, innocent) down one column, and you fill in the other column with characters’ names at the beginning of play. Then you should be able to match by row later on. This is all entirely untested, though, so sorry if it’s a dead end.

One other hitch I foresee you running into is that players may type periods into your characters’ names (“Mr. Smith”) and Inform might assume they are issuing two separate commands. So you’ll want to remove those periods before checking for a match (I think there’s an extension?), or perhaps phrase the question as just “Last name?” or something like that.

What you’re probably thinking of is a global variable, which you can use to store pretty much any value. To create one, you just say something like:

The chosen name is a text variable. The chosen name is “Biggins”.

I take it, though, that you don’t want to assign the name to the variable at startup, and instead are going to assign it randomly or have the player key it in. The latter requires more work, so I’ve presented a quick example here:

[code]The registry is a list of texts that varies. The registry is {“Hartford”, “Biggins”, “Branscomb”}.

The chosen name is a text variable.

Restaurant is a room.

After looking in Restaurant:
say "There is a list of names here: ";
repeat with item running through the registry:
if item is not entry 1 of the registry, say ", ";
say “Mr [item]”;
say “.”

Choosing a name is an action applying to one topic. Understand “I am Mr [text]” or “I am [text]” as choosing a name.

Carry out choosing a name:
let T be an indexed text;
let T be “[topic understood]”;
let T1 be an indexed text;
repeat with count running from 1 to the number of entries in the registry:
let T1 be “[entry (count) of registry]”;
if T matches the text T1, case insensitively:
say “Greetings, Mr [T1].”;
now the chosen name is entry (count) of the registry.

Every turn when the chosen name is not “”:
say “After a few moments, a large burly man walks in and says, 'I am Mr [the chosen name]! Who is that impostor?”;
end the story saying “You have been discovered!”

Test me with “I am Mr Biggins”.[/code]

This doesn’t deal with the case of a “Mr” having a period after it, but you can use a regular expression to delete it (in an “after reading a command” rule) if it’s actually going to be a component of your game.

–Erik

You can also use Emily Short’s extension “Punctuation Removal”; its documentation tells you how to easily strip the periods from things like “Mr. Biggins” in commands.

But as I understood your other thread, you want to assign the text at random and have the player discover it somewhere and use it somewhere else – to do that you can just have a table with the possible answers (or a list, but tables use less memory), choose something randomly from it when play begins, and store it in your global variable.

Hi all,

thanks, fascinating! I let you know how I get on. I’m sure I’ll be back with something else soon.

N