I7: A More Efficient Rule

Hello and Happy Thanksgiving all,

I’ve read up to chapter 7 in the Inform manual, and have been trying to get a better handle on the grammar rules. Every now and again I will try to implement some random example of either my own or the manual’s making in order to see if I’ve gotten a somewhat firm grip on what I just read.

I wrote this small bit in response to Chapter 7.13.

Lab is a room. The description of the Lab is "A pristine white lab, completely empty."

East of the Lab is the Storage Room.

Trolly is in the lab. Trolly is a vehicle. 

Instead of going to the Storage Room:
	if the player is not in a trolly, say "You can't enter there without a vehicle";
	if the player is in a trolly begin;
		say "You roll faster than your average turtle, for all of a few boring seconds.";
		move trolly to the Storage Room;
		try looking;
	end if.

The idea is that I want to prevent the player from entering the Storage Room, unless he is in a vehicle. Which the code above does just fine. But, I feel what I wrote is a bit verbose, and there probably is a shorter way of accomplishing the same using some kind of negative modifier. For example,

Instead of going to the Storage Room in other than the Trolly:
	say, "You can't enter there without a vehicle.";
Instead of going to the Storage Room:
		say "You roll faster than your average turtle, for all of a few boring seconds.";
		move trolly to the Storage Room;
		try looking;	

Which, does not work. I suspect it is because there might not be such a negative modifier. But I could be wrong. If there is, I’m curious if there is one or if there is a more efficient way of writing what I wrote out.

On a side note, when I tried doing,

		(the first code listed, up until the move line)
		try going east; // instead of move trolly to the Storage Room;
		(the rest)

I manage to bring up a bunch of errors in inform 7. Then I realized it was because my rule for “going to the Storage Room” was recursively calling itself. Is “Moving” a more conventional means of moving the player or would trying directions be more conventional?

I’m not quite sure what you mean by efficiency, but I like to use the “unless” condition a lot as a timesaver. Instead of writing something like:

[code]A red marble, a blue marble, a green marble, a yellow marble, and a purple marble are in the bag of marbles.

Check taking a marble:
if the noun is the red marble or the noun is the blue marble or the noun is the yellow marble or the noun is the yellow marble:
say “You only roll with green marbles.” instead.[/code]
You can just write:

Check taking a marble: unless the noun is the green marble: say "You only roll with green marbles." instead.
You’re mostly on the right track about the reasons the codes you posted don’t work. One minor thing is that the only reason you had to add “try looking” after moving to the Storage Room is that you used Instead rules, which required you to move the Trolly/player, thereby circumventing the normal process of going somewhere (which includes looking after you arrive). You’ll also crash the game, as you noted, anytime you write something that amounts to “Instead of going east, try going east”.

Unless you really want to, you don’t need to go out of your way to do either of those. You can just let the normal rules apply (these are rules that apply to the “going” action), and add a small check to see if the character is in the Trolly. Any of the following examples do that:

[code]Lab is a room. The description of the Lab is “A pristine white lab, completely empty.”

East of the Lab is the Storage Room.

Trolly is in the lab. Trolly is a vehicle.

Before going east in the Lab:
unless the player is in the Trolly:
say “You’re too lazy to walk over there. Why not ride the Trolly?” instead.

Check going:
if the room gone from is the Lab and the room gone to is the Storage room:
unless the player is in the Trolly:
say “It’s too far. You feel compelled to use the Trolly.” instead.

Instead of going from the Lab to the Storage room:
unless the vehicle gone by is the Trolly:
say “It must be at least 30 feet from here to there! That Trolly sure looks inviting.”;
otherwise:
continue the action.

[note that since this next one directly moves the character, adding a “try looking” would be necessary to print the room description of the Storage Lab after moving there]

Instead of going east in the Lab:
if the player is in the Trolly:
move the Trolly to the Storage Room;
say “You take the Trolly for a spin and end up in the Storage Room.”;
otherwise:
say “Ugh. You don’t really want to walk that far, do you?”.

Instead of going from the Lab to the Storage Room:
if the player is in Trolly:
continue the action;
otherwise:
say “As a matter of principle, you refuse to go to the storage room unless you are in your sleek, supercharged Trolly.”.
[/code]
For the most part, the words “Before”, “Check”, and “Instead” are interchangeable in the above examples (although you’d want to get rid of the word “instead” inside the lines of the rule if you changed the “Before” rule or the “Check” rule with an “Instead” rule, and would need to add the word instead after the final line of each branch if you changed one the “Instead” rules to a “Before” or “Check” rule).

In general it’s best to avoid Instead rules, since they skip so many of the processes built into regular actions, are not counted as actually having happened (in case you’d like to check later) without special extra steps, and usually prevent you from having “After” or “Report” rules which come in handy sometimes.

I’m not sure I really answered any of your questions. If not, please continue asking.

p.s. Although it’s probably obvious, if you run the example with all the various ways of going you’ll need to comment out all but one of the Before/Check/Instead rules at a time.

Mmm, I will keep that in mind in the future. Thank you for your other suggestions; It’s given me more options to consider when doing or trying to accomplish certain effects.