Picking up animal after it becomes tired from running

So I’m brand new to Inform 7, and I apologize if I my explanation of my problem is hard to understand. What I want to accomplish: Make a rat carryable after chasing it. Simple enough, but I can’t for the life of me figure it out. Here’s my code:

ratTired is a truth state that varies.
ratTired is initially false.

chasing is an action applying to one visible thing. Understand "chase [something]" as chasing.

Check chasing:
	if the noun is not an animal, say "You cannot chase this."

Carry out chasing:
	if chasing rat:
		say "You chase the rat for a while until it becomes too tired to run away.";
		now ratTired is true.
		
if ratTired is true:
	instead of taking rat:
		now rat is carried by player;
		say "You were able to snatch the rat!"
			
Dimly Lit Room is a room. "You are in a dark room. Your stomach is in excruciating pain from hunger. You need to find something to eat, fast."

a rat is an animal in dimly lit room.

-----------------------------------END----------------------------------------
The code works somewhat, but from the start of the game I can immediately pick up the rat. Can anyone help me here? I don’t know how to format these posts properly to show text, I apologize.

2 Likes

For formatting, there’s a button that looks like </> in the top bar. Select your code, then click that.

I’m guessing something is wrong with your indentation, because as written, if [condition]: instead of [action]: shouldn’t even compile. But it’s hard to tell since the forum removes all indentation that’s not code-formatted.

Hi Jason and welcome to the forum!

It looks like you have “If ratTired is true” before “instead of taking rat.” As Daniel said, that doesn’t seem like it should be able to compile–but in any case, you’d want “if ratTired is true” to go after “Instead of taking rat:”. “if” checks and the like all have to go inside rules, so Inform knows when to do the checks.

However, just switching the order of those two lines will have a weird effect on taking the rat when it’s not tired. The instead rule runs, sees that ratTired is not true–and then stops, doing nothing! So you get no message at all. This can be taken care of by testing ratTired in the rule heading:

instead of taking rat when ratTired is true:
	now rat is carried by player;
	say “You were able to snatch the rat!”

Then this rule won’t run at all when ratTired is false, and you get the normal message for trying to take a person (animals are a kind of person). Though you’d probably want to write a custom message.

You can do a similar thing for your carry out rule–which won’t affect the code’s behavior, but is a little easier to write:

Carry out chasing the rat:
	say “You chase the rat for a while until it becomes too tired to run away.”;
	now ratTired is true.

Also, your check rule doesn’t actually stop the action! If you add the word “instead” on the end, then it’ll stop the action. (With this code it doesn’t make a difference, because there aren’t any other rules for the action, but in other cases it might.)

Check chasing:
if the noun is not an animal, say “You cannot chase this.”

Okay thank you for teaching me that. The formatting as I have it should be showing now

Thank you so much for the quick reply! The code works now and I learned a thing or two, which is awesome. While I have you, do you think you could explain the difference between semi-colons and colons to me? The documentation information on it is a bit confusing to me.

Colons introduce a new “block” of code, while semicolons separate lines within the same “block”.

For example:

Instead of jumping: [Colon starts a new block, which will run instead of jumping]
    say "You're jumping!"; [Semicolon continues the block]
    increment the jumping counter; [Semicolon continues the block]
    if the jumping counter is greater than five: [Colon starts a new block, which will run if the jumping counter is greater than five]
        say "And you've jumped [jumping counter] times now!". [Period ends the entire thing: all blocks are over now]

By the way, instead of using ratTired, a more natural-language-istic approach makes this a property of the rat. You can refer to such states in the headings of rules, aiding readability.

The rat can be energetic or tired.

Chasing is an action applying to one thing. Understand "chase [something]" as chasing.

Check chasing:
	if the noun is not an animal, say "You cannot chase this."

Carry out chasing the rat:
	say "You chase the rat for a while until it becomes too tired to run away.";
	now the rat is tired.
		
Instead of taking the tired rat:
	now rat is carried by player;
	say "You were able to snatch the rat!"

Dimly Lit Room is a room. "You are in a dark room. Your stomach is in excruciating pain from hunger. You need to find something to eat, fast."

Also, you want the verb to apply to a thing, not a visible thing. The latter class includes nonexistent concepts like up, down, north, and in; the former, only physical objects existing in the world. So things are actually a subset of visible things, even though the terminology suggests the opposite.

1 Like

Good point Chris! Here’s one of many discussions we’ve had about “visible thing” vs. “thing,” and the [any thing] token. That’s an issue that perennially confuses people.

Another option:

The can't take other people rule does nothing when the noun is the rat and the rat is tired.

(Not checked, but that saves you from doing it with an instead. I might be wrong that an animal is considered a “person” for Inform’s purposes.)

1 Like

This is what I use for picking up my cat (take cat):

The can take cats rule is listed instead of the can't take other people rule in the check taking rules.
Check an actor taking (this is the can take cats rule):
	if the noun is a person and the noun is not a cat:
		say "I don't suppose [noun] would care for that.";
		stop the action.

Living Room is a room.

The cat is a female animal in Living Room.
The description of the cat is "My cat Alice is a shorthair Siamese who loves affection and attention."

The cat is wearing a silver collar.
The description of the silver collar is "The engraving says 'My name is Alice. If you find me, please call 613-555-1534 and ask for John'."

Every turn when the player is in Living Room:
	if the player carries the cat:
		say "[one of]Alice purrs loudly on your lap as you pet her.[or]Alice rubs herself against your face.[or]Alice looks at you with loving eyes.[in random order]".

Just change cats to rats and cat to rat. This should work for you.

Cheers.

1 Like