New actions errors?

Working on adding 2 new actions - scanning and clicking to simulate interactions with a computer. My code is as follows, but I receive the error "Clicking is an action applying to one visible thing and requiring the computer’: but an action can only apply to things or to kinds of value, for instance: ‘photographing is an action applying to one visible thing’ "and “You wrote ‘Scanning is an action applying to one visible thing and requiring the computer’: again, an action can only apply to things or to kinds of value.’” I cannot figure out what my error is.

Clicking is an action applying to one visible thing and requiring the computer. Understand "click [something]" as clicking.
Understand the command "click" as something new.
Carry out clicking:
	say "You can only click on something on the computer."
If player clicks on computer:
	say "A log of all the hotel rooms is pulled up. They are all vacant except room 237."
	
Scanning is an action applying to one visible thing and requiring the computer. Understand "scan [something preferably held]" as scanning.
Understand the command "scan" as something new.
Carry out scanning:
	say "That does nothing."
If player scans key cards:
	say "The scanner peeps. The key card is now activated."
	now key cards are the matching key of Door 237. 

In the phrase [Something] is an action applying to one visible thing and requiring [a requirement], the requirement can’t just be anything; there is only one phrase that works there. You can say requiring light, but not “requiring [something else].”

There are two other types of errors that I notice that haven’t yet been reported, probably because the compiler is tripping over the “and requiring” phrases before it gets to them. One is that you write

Understand "click [something]" as clicking.
Understand the command "click" as something new.

You’re defining the click action, but then telling the compiler to forget your definition, which means that “click [something]” won’t do anything in-game: you told the compiler to forget your definition! You can switch the order of the statements, which would be equivalent to saying “Forget what you already know about the click command. Now, here’s a click command.” (This is not really necessary either – Inform doesn’t have a pre-existing definition of click or scan – but neither does it hurt, provided that you’re not clearing out your own definition that you already wrote.)

The other problem I notice is this definition:

If player clicks on computer:
	say "A log of all the hotel rooms is pulled up. They are all vacant except room 237."

… and its equivalent, If player scans key cards, for the scanning action. The problem is that it needs to be defined in terms of Inform’s basic action sequence, and if doesn’t do that: it needs to be written as one or more before, check, instead, report, carry out, and/or after rules. (If you prefer to think about it syntactically, you can’t start a rule definition with if in Inform; if statements can only occur inside rules.) There’s several different ways to do this and they’re all pretty much the same in how they work.

Putting all that together, I took a shot at rewriting the scanning action in a way that should work and that illustrates these issues:

Hotel Lobby is a room. The computer is in Hotel Lobby. Some key cards are a plural-named thing in Hotel Lobby.

Room 237 is a room. door 237 is a locked door. door 237 is west of Hotel Lobby and east of Room 237.

Scanning is an action applying to one visible thing. Understand "scan [something]" as scanning.
Check scanning when the player cannot see the computer:
	instead say "You'll need to use the computer to do that."
Instead of scanning:
	if the noun is not key cards:
		say "That does nothing.";
	otherwise:
		say "The scanner peeps. The key card is now activated.";
		now the key cards are the matching key of door 237.

EDIT. Whoops! This works except for one thing, which I’d forgotten: it’s not possible to change the matching key of property during play!

This is kind of an awkward problem to have because doing a good solid realistic job of fixing it would require re-implementing a handful of rules controlling how movement, doors, and locking work, and it would be hard to be sure you got it right.

Here’s what I’d do to fake it fairly well, though. First, I’d change the instead rule to

Instead of scanning:
	if the noun is not key cards:
		say "That does nothing.";
	otherwise:
		say "The scanner peeps. The key card is now activated.";
		now door 237 is unlocked.

You then have the problem of wanting to make sure that the player can’t just walk in without the key; I’d write a quick rule to prevent that:

Instead of going through door 237 when the player does not have the key cards:
	say "You'll need a key card to get into this room.".
2 Likes

I was starting to post a reply here, but Patrick’s awesome answer is much better than the one I was working on! Just a couple small things:

I think this is just a syntax thing: “Now the matching key of door 237 is the key cards” should work with your original code, which is a little easier than the new work-around I think (the player would be able to re-lock the door, for example). NB your original code also needs door 237 to start out closed and locked – just flagging that for the OP.

And is there a reason you did an Instead rule rather than a Carry Out? Latter might be easier so conditions like “If we have scanned the key cards” work the way they ought to.

1 Like

Very fair! I tend to think that bunching everything up in a single instead rule is the easiest way to write a simple example (otherwise I’d probably break it into check/carry out/report rules), but it doesn’t track successful actions in a way that the code can check for later because, of course, the action didn’t succeed.

Darnit! That was the syntax I was looking for. Thank you. You’re also right that the door should start out closed and locked.

1 Like

Very helpful thank you so much! I used the same edits to figure out the clicking action as well! The if vs. instead vs. carry out has always confused me now I feel more clear about those differences.

1 Like

Super glad to be helpful!

As far as instead vs. carry out goes: All actions have six different rulebooks (before, instead, check, carry out, report, and after) that handle different parts of the action. Often, you can cram all of the processing into one rule if you want to, and I did that so I could write a simple example of what you were asking about. But @DeusIrae is right: using instead here means that the action didn’t technically succeed, and that might come back to bite you if you want to check later whether it happened.

Often, if all you want is a custom response, just writing an instead rule is the easiest way to get that: think of it as “instead of what you’d do by default, do this other thing in this particular circumstance.” But you could also break it down into separate rulebooks for the different parts of action processing, and that’s arguably more “correct”; in any case, it better meshes with the internal action-processing that Inform does. (There’s rarely a need to write a rule for all six action rulebooks; two or three is not uncommon, though.)

Just as an example, here’s a way to re-write that as a set of separate rules that explains what it might look like:

Scanning is an action applying to one visible thing. Understand "scan [something]" as scanning.

Check scanning when the player cannot see the computer:
	instead say "You'll need to use the computer to do that."

Check scanning when the noun is not key cards:
	instead say "That does nothing.".

Carry out scanning:
	now the matching key of door 237 is the key cards.

Report scanning:
	say "The scanner peeps. The key card is now activated.".

Does that make sense?

1 Like