Every turn, character taking something

I’m retrofitting a few examples to see how they work. I tried this:

Corinth is a room.

There is a woman called the Enchantress.
The Enchantress is in Corinth.

A mirror is scenery in Corinth.
A supporter called the pedestal is in Corinth.

A container called the bag is in Corinth.
The bag is closed.
Some bird feed is in the bag.

Every turn:
	if the Enchantress can touch something (called the item) which is not carried by a person:
		try the Enchantress taking the item.

Report the Enchantress taking something:
	say "The Enchantress takes [the noun] and tucks it into her robe." instead.

However if you run this, the Enchantress never takes anything. The only thing she could take here is the bag but it never happens. I’m finding the descriptions, as described in the manual, work a little differently than described. The example “Lean and Hungry” shows a thief taking “something valuable” and that example does work. Here I’m just having the Enchantress try to take “something” and that doesn’t seem to work.

I tried refining to this:

if the Enchantress can touch something visible (called the item) which is not carried by a person:

Here just making it “something visible” rather than plain “something”. But that also doesn’t work: the Enchantress still takes nothing.

If you turn “actions” on, you will see that what’s happening is that the Enchantress is trying to take the player every turn:

This doesn’t produce a message because, I think, the rules that print messages for unsuccessful actions don’t run for spontaneous actions by other people. (Definitely the “unsuccessful attempt” rules which would print “The Enchantress is unable to do that” only run when you’ve asked the Enchantress to do something. I don’t know if there are any other rules that standardly print something when an action by an NPC fails.)

The reason it tries taking the player every turn is because when you test “if the Enchantress can touch something (called the item) which is not carried by a person,” Inform tests things in some standard order instead of choosing one randomly, and the player is always the first thing in that order.

So if you want this to work you’ll have to define some adjective that defines the things the Enchantress can take and restrict her possible targets to that.

Or you could try this cheap trick:

Every turn: repeat with item running through things which can be touched by the Enchantress: try the Enchantress taking the item; if the Enchantress holds the item: break.

which yields:

so the Enchantress goes through trying to take everything, until she succeeds (and then “break” stops the loop). But since all the unsuccessful takes fail silently, it just looks like she took the first thing she could take.

Thanks for the breakdown, very helpful. I keep forgetting about that actions command so I’ve now added it to the start of all my test statements.

Matt’s solution is brilliant. I’ve also defined adjectives to do the same thing.

[code]A thing can be stealable.

Definition: a thing is stealable if it is not a person and it is not the player and it is not fixed in place and it is not enclosed by a person and it can be touched by the person asked.[/code]

[rant=code][code]“Thievery”

Corinth is a room.

There is a woman called the Enchantress.
The Enchantress is in Corinth.

A mirror is scenery in Corinth.
A supporter called the pedestal is in Corinth.

A container called the bag is in Corinth.
The bag is closed.
Some bird feed is in the bag.

Every turn:
if the Enchantress can touch a stealable thing:
try the Enchantress taking a random stealable thing.

Report the Enchantress taking something:
say “The Enchantress takes [the noun] and tucks it into her robe.” instead.

A thing can be stealable.

Definition: a thing is stealable if it is not a person and it is not the player and it is not fixed in place and it is not enclosed by a person and it can be touched by the person asked.[/code]

Corinth
You can see the Enchantress, the pedestal and the bag (closed) here.

actions
Actions listing on.

z
[waiting]
Time passes.
[waiting - succeeded]

[the Enchantress taking the bag]
The Enchantress takes the bag and tucks it into her robe.
[the Enchantress taking the bag - succeeded][/rant]

The utility of this is if you have multiple characters, you can make lists of things they want with different adjectives.

[code]a thing can be desirable.

Definition: A thing is desirable if it is stealable and it is the priceless ruby or it is the blank check or it is the royal jewels or it is lime-colored.

A thing can be lime-colored.

the kiwi is a thing. It is lime-colored. The avacado is a thing. It is lime-colored.[/code]

Be very careful with that: “a thing can be X” makes a boolean member variable, “Definition: a thing is X if” makes a function which takes an object and returns a boolean value. If you mix the two of them, the “Definition” wins out, which is what happens here. But having effectively two properties with the same name can lead to VERY subtle bugs: in that example, you can say “now the pineapple is desirable” and “now the pineapple is not desirable”, but they’ll do absolutely nothing.

Hmn. Thanks. I got a little fancy there, but for the initial way I duplicated your results, is that workable? (IE, don’t put in “if it is the tomato or if it is the helicopter or if it is [another defined adjective]”?

You should not declare both “A thing can be foo” and “Definition: a thing is foo if…” for the same adjective “foo”.

Did not know that! I thought it was a shortcut for declaring adjectives on every thing.

Either declaration defines an adjective “foo” on things. If you do both, one of the adjectives gets squashed by the other one, as Draconis said.

Okay cool, so do one or the other.

Is this construction valid, then, so long as I don’t also include “a thing can be desirable” and “stealable” and “lime-colored” are both also defined one way or the other?

Definition: A thing is desirable if it is stealable and it is the priceless ruby or it is the blank check or it is the royal jewels or it is lime-colored.

Looks right. Although I’m not sure how Inform associates and/or logic – you might need to use parentheses.