Defining Actions / Preventing the player from doing an action unless a requirement is met

Hello all!

I’m a complete beginner to Inform 7, and I thought I could use a variable for this, but that didn’t work.

I tried to have the player only being able to get up if they were on a supporter. Initially I tried to let the system check if the player was on a supporter. When that didn’t work, I tried a number of different ways. Nothing seemed to work.

The only demonstrations of requirements for actions seemed to involve the player having something in their inventory. But how do you make requirements that involve things like numbers, time etc.?

1 Like

The command >GET UP already maps to the exiting action per the Standard Rules. And, in fact, there’s already a rule called the can't exit when not inside anything rule (also provided by the Standard Rules) to do what you’re asking. This produces output like:

>GET UP
But you aren't in anything at the moment.

You’ll probably get better advice if you include the actual code that you’re having trouble with in your post. You can use the editing controls to mark it as code, which is helpful for those trying to assist.

1 Like

Hi Philip, can you provide an example of some code you tried that didn’t work? You can put code between sets of three back ticks (‘’’) on a line by themselves to get nice formatting.

The thing I attempted to do, I have partially succeeded in doing by installing the extension Postures, by Emily Short. But the thing that still eludes me is how you put requirements on actions, and why some of the code works in certain cases.

Example:

Instead of getting up,
say “You bump your head on the ceiling as you rise.”

(also tried “standing”)

Doesn’t work.

Instead of looking,
say “You bump your head on the ceiling as you rise.”

Works.


The thing which is most vital to getting started, I think, is knowing how to put requirements on actions. One example would be having to have a key to open a door etc.

I tried to have a number which is added or subtracted from depending on whether the player was upright. I tried some different things I thought might work. Sadly, I deleted it when I tried something new.

*I think the extension has solved the problem of only being able to stand / get up when you are down has been solved. But I have made some attempts to define the verb “rise from” to mean the same thing, only I had an issue with the player being able to rise multiple times and without being down. Now, I think it works, but it would be useful to know how to define a verb in such a way that it can only be done in a special circumstance.

This doesn’t work because getting up is not an action which has been defined in the Standard Rules. Postures doesn’t define it either, but it does define standing up.

This does work because looking is a defined action.

Your example of a key to open a door is already implemented in the standard rules by declaring the door to be lockable, and to set the door’s property matching key to the thing that is the key for the door.

You might be interested in the standard rules to see how this is done: Standard Rules by Graham Nelson

When an action rule doesn’t seem to be firing, try the ACTIONS command.

>actions
Actions listing on.

>get up
[exiting]
But you aren’t in anything at the moment.
[exiting - failed the can’t exit when not inside anything rule]

Inform has a bunch of ways that a player can trigger a particular action: you can “get”, “take”, or “pick up” a thing, for example. But the action in the code only has a single name, “taking”. The ACTIONS testing command tells you the code name for each action you try, so you can find out that “get up” means “exiting”.

Thank you, that solved the initial problem. There is also the problem of the player seemingly being able to recline, sit, and stand everywhere. I can solve this by adding “Instead…”, after all it’s mostly realistic, but I had in mind that the player might not want to lie down on the ground and if there was a way to redefine the action.

Also, how do I equate a new verb with an existing verb, i.e. “rise” and “rise from” meaning the same as “get up” or “exiting”. Presently, neither is an understood verb. I tried to use “Understand” and “Rise is an action applying to …”. I read the documentation on this, but I’m not certain how to apply it or if there’s a simpler way.

(+1)

When player “exits” the bed, (I changed “instead” to “before”), they end up in room again as if the supporter / bed is a location. Is there a way to stop this?

(+2)

If I write:

Before exiting,
instead say “You bump your head on the ceiling as you rise.”

The action isn’t completed. It’s because the “instead”, I figure. Is there a way to change what is being replied to the action, though the action is still completed?


I figured out how to list responses, by typing “responses” – but those seem to only be for breaking rules. Is there a way to change responses like “You get onto the bed.” etc.?

I tried to alter the response for the block sleeping rule, as I saw here:

14.11. Changing the text of responses.

The print block sleeping rule response (A) is “The time for sleeping is past.”

But it didn’t work.

Let’s deal with the command verb first.

The exiting action, which is defined in the Standard Rules, is an action applying to nothing. So

Understand "rise" as exiting".

will work fine, but

Understand "rise from [something]" as exiting".

will not (because the exiting action doesn’t involve a [something]).

There is a “getting off” action which does take an object. In fact, the exiting action redirects to getting off whenever the player tries exiting from a supporter. So you could work with that action instead. But you might want to be able to EXIT FROM CUBPOARD, say, where the noun is a container rather than a supporter, and the Standard Rules do not allow for this. So I’m going to assume we’re dealing with the exiting action.

To make it work, you can define a new action which takes an object, but just redirects to exiting.

Exiting from is an action applying to one thing. 
Understand "exit _/from [something]" as exiting from.
Check exiting from when the noun does not hold the player:
	say "You aren't [if the noun is a supporter]on[else]in[end if] that." instead.
Carry out exiting from:
	try exiting instead.

(The _/from in the understand line makes the word “from” optional.)

We can now just make “rise” a synonym for “exit” (in all contexts):

"Understand the command "rise" as "exit".

Now EXIT, RISE, EXIT BED, EXIT FROM BED, RISE FROM BED will all work (as will RISE BED, and various other synonyms for exit defined in the Standard Rules. (This will include some commands which are not strictly grammatical, such as “OUT BED”. You should persuade yourself that this does not matter.)

You can check all of the commands leading to the exiting action by clicking on it in the Actions Index. (It will list all the commands accepted by your game, including the ones from the Standard Rules and the ones that you have defined yourself.) You can also look up the getting off action, and the exiting from action that we just defined.

Now for the outcome/report question. The issue here is understanding what you want to happen. You say that you don’t want the player to end up back in the room when they exit. So where do you want them to end up?

If you want to change how the action actually functions assuming that it works, you can write a carry out rule. The Standard Rules provide carry out rules for exiting and getting off (imaginatively called the “standard exiting rule” and the “standard getting off rule”), which simple move the player from whatever container/supporter they are in, to whatever is the the holder of that container (usually a room). If you want to do something else, you can simply write a more specific carry out rule. (This would have the preamble Carry out getting off the four-poster bed. Note:- getting off rather than exiting, because exiting a supporter redirects to getting off automatically. )

It seems more likely that what you want to do is change what is reported back to the player when the action completes. There are two built-in mechanisms for this.

The first is the Report rules, which normally run after an action completes successfully. The Standard Rules has two report rules for exiting (and two more for getting off, which are basically the same). The first is the “standard report exiting rule”, which merely says “You get out of the cupboard”, or similar. The second is the “describe room emerged into rule”, which prints a room description. You can suppress these rules if you want to, with something like:

The describe room emerged into rule does nothing when the player was in the cupboard.
The describe room stood up into rule does nothing when the player was on the four-poster bed.

(I don’t think I’d advise this approach.) And you can write your own new report rules. Like all rulebooks, the report rules get ordered by specificity. All the applicable report rules will run, unless you terminate the rulebook with an instruction like “stop the action.”

A “lighter-touch” way to go about things is to use After rules. These run after an action completes successfully, but before the report rules. By default, any after rule will terminate the action (cutting off any less specific after rules, and all report rules. You can prevent this if necessary, with a “continue the action” instruction.) So if you want the special case of leaving the four-poster bed to report differently from a generic exiting action, just write an after rule to cover it. (It will have to be an “After getting off the four-poster bed” rule, because exiting will have redirected to getting off by that point.)

You can discover the names of the rules which are firing for a given action in several ways: if you type RULES while testing in the IDE, the game will report the names of all the action rules that fire. If you look up an action in the actions index, it will tell you all the associated rules for that action. And you can consult the Standard Rules directly to see what the rules are actually doing under the hood.

Omit the word “print” and it will work.

Thank you. I think this has solved most of my problems.

Is there a way to make an action depend on a varying number?

Tiredness is a number which varies. Tiredness is initially 0.

Every turn:
increase tiredness by 1.

Works. Now, what I would like to do is make it so the player is only able to sleep if tiredness is more than a certain number. I would also like to know how to change the number to 0 again, after the player has slept, but I figure “now tiredness is 0” will work where I also write how much time has passed.


I have written this redefining how sleep works, much of which I picked up online. I’m going to add a passage of time associated with sleeping, and maybe dream sequences as well. (But I have found examples of how to do that.)

Include Postures by Emily Short.

The player is in Abandoned Hovel.

Tiredness is a number which varies. Tiredness is initially 0.

Every turn:
increase tiredness by 1.

A person is either awake or asleep. A person is usually awake.

A check sleeping rule:
if the player is not on a supporter:
say “You are unable to sleep while standing.” instead.

The block sleeping rule is not listed in any rulebook.

After sleeping: now the player is asleep; say “You fall asleep.”

Instead of doing something other than waking up, waiting or sleeping when the player is asleep:
say “Deep within the realms of dreams and terrors, you are unable to do that!”

Instead of sleeping when the player is asleep:
say “Zzzz.”

Instead of waking up when the player is asleep:
now the player is awake;
say “You come to suddenly, wiping drool from your lips.”


Instead of lying down:
if the player is not on a supporter:
say “You don’t feel like lying down on the ground.” instead.

I’m trying to forbid the player from lying down on the ground. I have checked that the verb is “lying down”, and it does work for other verbs. I’m thinking it has something to do with the extension. Is there a rule I have to forbid or change, or what is going on?

Yes, there are various of ways of doing this. If you just want to block sleeping when tiredness is too high (say 5):

Check sleeping when tiredness is at least 5:
      say "You're not tired enough to sleep." instead.

(Or you could make it an Instead rule, with practically identical effect.)

“Now tiredness is 0” will reset it; just drop it into a convenient rule.

The problem is that Postures already provides an Instead of lying down rule (the convert lying down rule), and it gets in before your rule and changes the action to something else.

You can fix this by making sure that your rule is more specific than Emily Short’s rule; you can easily do this by running your if clause into the preamble:

Instead of lying down when the player is not on a supporter:
      say “You don’t feel like lying down on the ground.”

(note: you don’t need your final “instead”, since this is an Instead rule. Not that it does any harm.)

But this isn’t the best way of going about things. Postures defines an adjective posture-friendly, applying to rooms. If a room is not posture-friendly, the player can’t sit or lie down in it. You can prevent lying down in all rooms with

A room is usually not posture-friendly.

This will give the response “There’s nothing to lie on” when the player tries to lie down in a room with no suitable supporter. (If there is one, Postures redirects the player to try lying on it instead.) If you want to change that response:

The convert lying down rule response (B) is “You don’t feel like lying down on the ground.”
1 Like