Question about text variables

In my game I am trying to create a ‘magic’ word and put it in a text variable. I want it to be a random choice between five words that I made up. The player would find this word in a book, and then be able to use this word at the appropriate time, in other words, once he finds it, the text variable into which that word is placed would remain constant throughout the rest of the game. I can’t seem to find a way to keep this text variable constant. I know that I can make it one and only one word by simply saying, eg. ‘magicword is “frotzle”’, but of course I have to do everything the hard way, I want it to be a random choice between five different words. How can I do this, and turn this choice into a constant? I want it to be ‘different’ for different players or playthroughs, at least random.

Thanks

Here’s one way to do it:

Test Chamber is a room.

The magic word is a text that varies.

When play begins:
	now the magic word is the substituted form of "[one of]xyzzy[or]plugh[or]plover[or]frotzle[or]frobnoid[purely at random]".

The player carries the book. The description of the book is "It falls open to a page that says '[the magic word]' in ornate gold letters."
	
Performing magic is an action applying to nothing.
[Can we avoid enumerating these?]
Understand "xyzzy" as performing magic when the magic word is "xyzzy".
Understand "plugh" as performing magic when the magic word is "plugh".
Understand "plover" as performing magic when the magic word is "plover".
Understand "frotzle" as performing magic when the magic word is "frotzle".
Understand "frobnoid" as performing magic when the magic word is "frobnoid".

To intone is a verb.
Report performing magic (this is the report performing magic rule):
	say "[We] [intone] the word '[the magic word]' in a commanding voice, and [our] eyebrows grow bushier." (A).

Test me with "read book / read book / read book / xyzzy / plugh / plover / frotzle / frobnoid".

The text variable doesn’t actually have to be a constant, so long as it’s treated as one. In other words, it’s set once when play begins (or when the player first reads the book) and is left alone after that. This relaxation allows us to set the variable based on computations done in a ‘when play begins’ rule that the compiler might not be willing or able to perform at compile time.

The enumeration of the magic words in understand statements isn’t ideal. The issue stems in part from a topic being distinct from a text, and in part from Inform not liking dynamic verb words because it needs to set up grammar entries. Balances (an I6 demo game with an Enchanter-like spell system) implemented spell names as verbs using the UnknownVerb entry point and mapping “failures” that matched memorized spell names to a special alternate version of the cast action. We could look at doing something similar at the I7 level here.

I think this would basically amount to creating an action on text that matched a “[text]” token, and then having our spell check whether the topic understood matched the magic word:

[code]Test Chamber is a room.

The magic word is a text that varies.

When play begins:
now the magic word is the substituted form of “[one of]xyzzy[or]plugh[or]plover[or]frotzle[or]frobnoid[purely at random]”.

The player carries the book. The description of the book is “It falls open to a page that says ‘[the magic word]’ in ornate gold letters.”

Performing magic is an action applying to one topic.
Understand “[text]” as performing magic.

Check performing magic (this is the failed spells are unrecognized rule):
unless “[the topic understood]” matches the text “[the magic word]”:
say “[text of parser error internal rule response (N)][line break]” instead. [this is just “not a verb I recogniz/se”]

To intone is a verb.
Report performing magic (this is the report performing magic rule):
say “[We] [intone] the word ‘[the magic word]’ in a commanding voice, and [our] eyebrows grow bushier.” (A).

Test me with “read book / read book / read book / xyzzy / plugh / plover / frotzle / frobnoid”.[/code]

It took an annoying amount of fiddling before I hit on ‘unless “[the topic understood]” matches the text “[the magic word]”:’ as the formulation for that line. Is there a more direct way?

We could also create the possible magic words as a value and have our action run on that:

[code]Test Chamber is a room.

A spell is a kind of value. The spells are xyzzy, plugh, plover, frotzle, and frobnoid.

The magic word is a spell that varies.

When play begins:
now the magic word is a random spell.

The player carries the book. The description of the book is “It falls open to a page that says ‘[the magic word]’ in ornate gold letters.”

Performing magic is an action applying to one spell.
[Can we avoid enumerating these?]
Understand “[spell]” as performing magic.

Check performing magic (this is the spell must be the magic word rule):
unless the spell understood is the magic word:
say “You sense a distant disturbance, as if the spell you uttered had some effect in an alternate universe; but in this universe, nothing happens.” instead.

To intone is a verb.
Report performing magic (this is the report performing magic rule):
say “[We] [intone] the word ‘[the magic word]’ in a commanding voice, and [our] eyebrows grow bushier.” (A).

Test me with “read book / read book / read book / xyzzy / plugh / plover / frotzle / frobnoid”.[/code]

(I didn’t make the text of my check performing magic rule adaptive, due to laziness.) This lets us write custom responses to the other possible magic words and may avoid some complications from an unrestricted “[text]” token.

I’d have liked to try this:

Understand "[spell]" as performing magic when the spell understood is the magic word.

but the “understand” line doesn’t work even when you use the magic word. I guess that “the spell understood” probably isn’t set at that stage of parsing. (You can write things like “…when the item described is the magic item” when doing an action on things, at least I think you can, but I’m not sure if you can do this for non-object kinds of value. Not sure how the internals work.)

Nice.

Performing magic is an action applying to one topic.
Understand "[text]" as performing magic.

produces (slightly edited for clarity):

[ UnknownVerb; verb_wordnum = 0; return 'no.verb'; ];
Verb 'no.verb'
    * topic  -> A77_performing_magic
;

Thanks Matt and Vince,

Actually my goal is probably going to be simpler than that, in that ‘magicword’ is actually going to be a say-able value("[text]")(that is, say-able by the player). I want the player to be able to SAY [magicword](without quotes), with a response immediately following–or not, depending on whether the player is in the right place, saying the right word at the right time(as opposed to saying it before reading the book–must allow for that case–must see the book first). Of course, I guess I may have to re-define the typed command “say” to permit speech without a partner…??

Great suggestions both, thanks

By the way, the affect of this word is like that of “Open sesame”…a ‘door’ will open as the result.

Well, I attempted to redefine “say” to have it apply to text—this was unsuccessful. But I think I solved the problem. I also decided I want the player to actually ‘whisper’ the ‘magicword’, so I also created the verb whisper. Since apparently we cannot create verbs that apply only to [text](? am I right?), I decided to make each of the five magic words ‘part’ of the player, putting them all under a kind called ‘headword’. That way, the player can refer to them without that nasty ‘You can’t see any such thing’ message. I created each of their ‘descriptions’ as “Just another one of your nonsense words”. The simple random choice routine as part of the “When the game begins:”, that you suggested, worked, and placed a text value into ‘magicword’. I wrote my rules like this:

Check whispering something: if the noun is not a headword: instead say "I doubt anyone heard you, much less understood you."; otherwise: if the printed name of the noun is magicword: if we have not examined Natalie's diary: instead say "Our contract clearly states that you have to actually 'find' the correct word, before you do this, even if you already know that word. Sorry, no shortcuts, no free rides!"; otherwise: if the location is not Closet Interior: instead say "Though you feel a slight tickle, nothing happens."; otherwise: instead say "Muttering nonsense words is something we thought you gave up in childhood." Check saying something: if the printed name of the noun is not magicword: instead say "Sorry, I don't think anyone is interested, or even listening."; otherwise: if we have examined Natalie's diary: instead say "Nothing happens. Remember what the diary said...."; otherwise: instead say "[the noun] is right!" After whispering something while the location is Closet Interior: if the printed name of the noun is magicword: say "You hear a sound like gentle chimes ringing. When it stops, you look around and notice a subtle change...."; try looking.
Just wanted to share this.

If you want an action to apply to text, you should define it as “applying to a topic”.

Whispering is an action applying to one topic. Understand "whisper [text]" as whispering. Carry out whispering: if the topic understood is...

Thanks draconis–didn’t know I could do that!