Planting tomatoes.

I’m having difficulty with this code for transferring one of a kind of object to an area. Here’s what I have right now.

Planting is an action applying to one visible thing.

Understand "plant [something]" as planting.

report planting: say "[noun] has been planted successfuly"

carry out planting:
	if player has tomato seed:
		move the noun to storage;
		move one tomato sapling to nursery.

a tomato sapling is a kind of thing.

39 tomato saplings are in storage.

nursery is east of land.

a tomato seed is a kind of thing.

25 tomato seeds are in storage.

storage is a room.

I am not 100% sure, but I think the game is having trouble with selecting the tomato sapling to move.


Let T be a random tomato sapling in storage; now T is in the nursery;

This could probably even be simplified to:

Now a random tomato sapling in storage is in the nursery;

Here are a few things to try:

1. This isn’t directly related to your problem, but you probably want the planting action to apply to “one touchable thing” rather than “one visible thing”. Otherwise, you might be creating a scenario where the player can plant a seed that’s visible but inaccessible. Inform understands “one thing” as a shorthand for “one touchable thing” (thus creating the oddity that “one visible thing” is actually a broader class of things than “one thing”), but it’s usually best to be explicit.

2. You’ll want a check rule to ensure that what the player is trying to plant is actually a seed.

3. You don’t need to define a “storage” room to hold off-stage objects; things can be left generically off-stage until needed, like so:

There are 20 tomato saplings. There are 20 tomato seeds.

Note that you need to define tomato seed and tomato saplings as kinds of things prior to creating these off-stage collections.

4. As it stands, your carry out rule would cause the sapling to appear in the nursery even if the player is nowhere near the nursery when he performs the planting action. Instead try this:

carry out planting: remove the noun from play; move a random off-stage tomato sapling to the location of the player;
This revised code will ensure that the sapling ends up wherever the player is (if you want to ensure that this is the nursery, see below). You should specify “off-stage” to make sure that Inform doesn’t grab a random sapling that’s already in play.

5. The test you have in your carry out rule is bad form; carry out rules should assume that the action is valid. If you need to make sure that it’s valid for the player to perform an action, you should use check rules instead:

[code]check planting (this is the can’t plant non-seeds rule):
if the noun is not a tomato seed:
say “You can’t plant that.”;
stop the action;

check planting (this is the can’t plant outside the nursery rule):
if the location of the player is not the nursery:
say “There’s no suitable soil in which to plant anything here.”;
stop the action;[/code]
These could be one rule, but it’s good form to have a separate check rule for each condition. The bits in brackets are optional - they’re there in case you ever need to refer to these check rules by name elsewhere in your code.

Incidentally, if you want there to be more than one room that’s suitable for planting (i.e., instead of just the nursery), you can use room properties to establish this. Like so:

[code]a room can be suitable for planting. a room is usually not suitable for planting.

check planting (this is the can’t plant outside the nursery rule):
if the location of the player is not suitable for planting:
say “There’s no suitable soil in which to plant anything here.”;
stop the action;


the nursery is suitable for planting.[/code]

Giving rules a name is actually even more useful than that. Inform has the special testing command “actions on”, which will tell you whether the current action has succeeded of failed. If you name the rules and the action fails, this will display the name of the rule causing the action to fail. This is extremely useful for debugging.

Hope this helps.

I’d like to thank everyone for all their help over the past few days! I can’t believe this isn’t even the hardest part of what I’m trying to code! I’m so glad there’re people I can count on when I need help!

I have to confess that I’m terribly curious whether these are contrived examples, or whether the game you’re working on really does revolve around tomatos.

I had assumed that Mike111 was probaby doing an IF version of Attack of the Killer Tomatoes.

Robert Rothman