Creating a New Action

I want the player to be able to wash things (only himself, currently) in a river or other water source (checking whether something is large enough to wash in will come later, if I decide to make more things in different sizes washable). I am basing this on the Eddystone example, and currently have [code]A thing can be dirty or clean. A thing is usually clean. The player is dirty.
A thing can be wet or dry. A thing is usually dry.

Instead of examining the player:
say “[if dirty]You are tired and worn from your travels, and your outward appearance reflects that. [otherwise if clean]You are still tired, but no one could guess that just by looking at you. [end if]”.

Understand “wash [something] in [something]” as cleaning it in. Cleaning it in is an action applying to two things.

Instead of washing something, say “Try specifying you want to wash [the noun] in.”

Check cleaning it in: if the noun is not dirty, say “[The noun] is already clean. Why wash it?” instead; if the noun is a person, say “You doubt [if the noun is female]she[otherwise if the noun is male]he[otherwise][the noun][end if] would appreciate that.” instead; if the second noun is dry, say “You cannot wash [the noun] in the dry [second noun].” instead.

Carry out cleaning it in:
The noun is now clean.

Report cleaning it in: say “You wash [the noun] in [the second noun], removing the dirt and grime.”[/code] This mostly works, but the line “Instead of washing something, say ‘Try specifying you want to wash [the noun] in.’” is giving me problems. In Eddystone this was used to see if the player left off the direction to turn the light towards, but I cannot figure out how to change it for my purposes, as the line I have now gives me an error:

Also, how would I allow the player to wash himself now that I have prevented him from washing people?

Finally, completely unrelated, but is there any way that I can get the chapter name, other than creating a variable and changing it to the name of current chapter at the beginning of each one?

You defined the action in code as “cleaning”. “Wash” is a grammar that you defined for the player to use in-game. There is no “washing” action in the code, which is why Inform is getting confused.

What you want is a way to handle cases where the player just types “WASH DISHES” without specifying what to wash the dishes in, right? For that, you need to do two things.

First, define another grammar line that makes it legal for a player to type that.

Understand "wash [something]" as cleaning it in.

Now, the game will still want to see a second noun. So write a rule for the “supplying a missing second noun” activity:

Rule for supplying a missing second noun while cleaning: say "Try specifying what you want to wash [the noun] in."

The cool thing about this is that you can add code to automatically pick something logical:

Rule for supplying a missing second noun while cleaning: if a wet thing is visible, change the second noun to a random visible wet thing; otherwise say "Try specifying what you want to wash [the noun] in."

See chapter 17.30 in the documentation.

The simplest way is to change the relevant if-then statment:

if the noun is a person and the noun is not the player, say "You doubt [etc, etc]."

Incidentally, you have all your “error checking” for the cleaning action inside one check rule. This is legal (that is, it compiles and it works), but a better method is to put each if-then inside a separate check rule. Each check rule will fire in sequence, stopping if it finds a problem.

[code]Check cleaning it in:
if the noun is not dirty, say “[The noun] is already clean. Why wash it?” instead.

Check cleaning it in:
if the noun is a person and the noun is not the player, say “You doubt [if the noun is female]she[otherwise if the noun is male]he[otherwise][the noun][end if] would appreciate that.” instead.

Check cleaning it in:
if the second noun is dry, say “You cannot wash [the noun] in the dry [second noun].” instead.[/code]

This makes it a lot easier to keep track of which rules are affecting the action, and when.

Thanks!

Oops! I had originally defined “cleaning it in” as “washing it in”, but changed it to see if I could fix some problems that way, and I guess I forgot to change all of the references to “washing”.

Actually, I was intending that the player had to specify what he wanted to wash the “noun” in, but I prefer the code you gave me that supplies the second noun automatically. However, is there any way that I can change that so it will chose some things over others ("…it is very likely"), or will the “random visible wet thing” automatically look for things like that?

I thought it would have something like that, but I wasn’t completely sure about how to word it.

Thanks again for the code and the help!

Finally, two questions. First, is there any way for me to get the name of the chapter (for example, to put in the status bar)? Second, how would I make a backdrop (called canyon) wet or dry depending upon whether a room beside the player is wet? Unfortunately, I only want this to respond if the wet room is in the gorge, and sometimes other rooms beside the player are wet as well. I wouldn’t want the player being able to wash himself in a gorge a few rooms away! :wink:

Edit:
I ran into another problem, and decided to place it here instead of in a new or an older thread.After doing something other than going a direction from the Tree: if the turn count is greater than 6; say "You wait until the the rain passes, and then you get out of your shelter and, rather quickly, leave the plains before a snowstorm comes."; end the game in victory. gives the problem report

“Random visible wet thing” will choose one wet thing in the room, at random. If there’s only one wet thing in the room, it will choose that one. If you anticipate having more than one wet thing in a room at once, and you want certain things to have precedence, you can set up some if-then statements to handle that.

Rule for supplying a missing noun while cleaning: if the sink is in the location, change the second noun to the sink; otherwise if a wet thing is in the location, change the second noun to a random visible wet thing; otherwise say "You will have to specify what you want to clean [the noun] in."

If by “chapter” you mean the name of a scene, then no. You can’t refer to “the current scene” because there could be any number of scenes running simultaneously.

The simplest way to do Chapters would probably be to just set up a global variable for the chapter name:

Current chapter is some text that varies.

Then change it manually at the appropriate time:

now current chapter is "Chapter 2 - The Storm".

You can print the value of “current chapter” with a simple substitution:

say "We are currently on [current chapter]."

I meant the chapter in the code, but I figured that I would have to use something like that example you gave me. Thanks for clearing up that “Random visible wet thing” question as well. However, do you know about that last error report that I got (in the edit of my previous post)?

Thanks!

The chapter/section headings you put in the code are just for your own reference. They are ignored by the compiler.

The clause “from the Tree” is a clause that is specific to only the going action. “Doing something other than going” involves actions other than going, so “from the Tree” won’t work there. Try:

Instead of doing something other than going when the location is the Tree:

You don’t have to say “going a direction”, although technically it’s correct – the grammar for going ensures that only a direction would be the noun in any case.

Thanks, but when I update the code, I get an error message (both shown below).Instead of doing something other than going when the location is the Tree begin; if the turn count is greater than 6 begin; say "You wait until the the rain passes, and then you get out of your shelter and, rather quickly, leave the plains before a snowstorm comes."; end the game in victory. otherwise; continue the action; end if; end if.

Hi Goldenrod. :slight_smile:

You’ve got some begin / end syntax confusion as well as a punctuaton mistake in there. First, the pramble of a rule (Instead of… etc.) is followed by a colon, not a semi-colon. Begin / end is not used for this. Also, only use the period at the end of a block. Try:Instead of doing something other than going when the location is the Tree:[colon here - no begin / end] if the turn count is greater than 6 begin; say "You wait until the the rain passes, and then you get out of your shelter and, rather quickly, leave the plains before a snowstorm comes."; end the game in victory;[semi-colon (not a period) here] otherwise; continue the action; end if.

Thanks for pointing that out! This should hopefully be the last question I have to ask in this topic, but how would I make a backdrop (called canyon) wet or dry depending upon whether a room beside the player is wet? I only want this to respond if the wet room is in the gorge, though, and sometimes other rooms beside the player are wet as well.

Your description of the conditions involved is a little bit confusing, but I’ll give it a shot. It sounds like you want the backdrop (the canyon) to be wet IF the player’s current location is wet, AND if at least one other room besides the player’s location is both in the gorge (which I assume is a region) and also wet. Correct?

You can change the status of the backdrop using a “now the canyon is…” phrase. You set up the specific conditions with an if-then statement.

if the location is wet and there is a wet room that is in the Gorge, now the canyon is wet; otherwise now the canyon is dry.

I’m not clear on whether you need the other room to be immediately next to the character’s location, or if it can be any room on the map. If the former, you can add the adjective “adjacent” to specify that the other wet room must be immediately next to the character’s location.

if the location is wet and there is a wet adjacent room that is in the Gorge, now the canyon is wet; otherwise now the canyon is dry.

Now you can’t just write that if-then statement by itself – you need to put it in a rule so the game knows when to check it. So how often does the game need to check to see if the canyon is wet or dry? If there are rooms turning wet or dry all the time in your game, you might want to check every turn. So:

Every turn: if the location is wet and there is a wet adjacent room that is in the Gorge, now the canyon is wet; otherwise now the canyon is dry.

Sorry that was confusing. I wanted the backdrop (the canyon) to be wet if at least one room adjacent to the player’s location is both in the gorge (which is a region) and wet. I didn’t care if the player’s location was wet, so I took that part out of the code and it works very nicely now. Thanks!

I know these posts are four years old, but they address creating a new action I’d like to implement in my new project. But after I put it all together, I get the following problem:

Problem. You wrote ‘The noun is now clean’ : but this is a phrase which I don’t recognise, possibly because it is one you meant to define but never got round to, or because the wording is wrong (see the Phrasebook section of the Index to check). Alternatively, it may be that the text immediately previous to this was a definition whose ending, normally a full stop, is missing?

I don’t think I removed anything from the example given in this thread, so why doesn’t Inform understand the simple sentence, ‘The noun is now clean’?

Try “now the noun is clean”.

The general form is defined as “now (condition to be made true).” That’s why it makes a difference where the “now” is.

If you’re creating a “cleaning it with/in” action, you’ll need to consider the fact that there is already a “rubbing” action defined in the standard rules. You’ll need to divert this action to the cleaning one so that the grammar works as expected.

Hope this helps.