Trying to Plant a seed into a seed

Some quick help why won’t the game let me plant a seed into some dirt with this code.

[code]Plot is a kind of container. Plots can be tilled or untilled.

Seed is a kind of thing. Tomato Seed is a kind of seed.

Tilling is an action applying to one thing. Understand “Till [something]” as tilling.

Check tilling:
if noun is a plot:
if noun is untilled:
continue the action;
otherwise:
Say “That soil has already been tilled.”;
otherwise:
say “That cannot be tilled.”

Carry out tilling:
now the noun is tilled.

Planting is an action applying to two visible things. Understand “Plant [something] into [something]” as planting.

Instead of inserting something into a plot:
try planting.

Check planting:
if second noun is a plot:
if noun is a seed:
if plot is tilled:
say “You gently dig a small hole and lovingly plant the seed.”;
continue the action;
otherwise:
say “The ground is to hard and needs to be tilled.”;
otherwise:
say “That cannot be planted.”;
otherwise:
say “You cannot plant this in just any ground.”

Carry out planting:
now the noun is in the second noun.

Small Field is a room.

Dirt patch is a plot in a small field. Understand “Dirt” as dirt patch.

The player carries a tomato seed. Understand “Seed” as tomato seed.
[/code]

I hope the error’s in this code somewhere.

Here’s wjat comes up

plant seed in dirt
I didn’t understand that sentence.

plant seed
(into the Tomato Seed)
You cannot plant this in just any ground.

[** Programming error: tried to “move” Tomato Seed to Tomato Seed, which would make a loop: Tomato Seed in Tomato Seed **]

Thank you in advance.

Two things:

  1. You specified “Plant [something] into [something]” as the correct syntax. This means that “plant [something] in [something]” is not valid - you have to use “into”.

Right now, the game is looking instead for a seed inside the plot, and trying to plant it into nowhere in particular. Since there’s no seed inside the plot already, it stops.

  1. Check out chapter 17.30 for supplying a missing second noun. This will help you ensure that your code intelligently seeks out plots instead of trying to plant the seed in whatever noun comes first to hand.

That activity doesn’t apply with this grammar setup. Use “does the player mean…” rules instead.

(“Supplying a missing second noun” is another possible approach, but it requires more grammar declarations as well as more rules.)

In your Check rule, you should also make sure that illegal planting actions are actually blocked, by writing “instead say ‘You can’t do that.’” rather than just saying it. That’s what is causing the programming error above; although you told the player he couldn’t do that, you then went ahead and did it anyway.

All the answers above point out valid issues. Anyway, here’s how I’d rewrite your example:

"Farmville"

A plot is a kind of container. A plot can be tilled or untilled.

A seed is a kind of thing. A tomato seed is a kind of seed. 


Tilling is an action applying to one thing. Understand "till [something]" as tilling.

Check tilling something which is not a plot:
	instead say "That cannot be tilled."	
Check tilling a tilled plot:
	instead say "That soil has already been tilled."
		
Carry out tilling: now the noun is tilled.

Report tilling: say "You turn over the soil in [the noun]."

Does the player mean tilling a plot: it is likely.


Planting it in is an action applying to two things. Understand "plant [something] in/into [something]" as planting it in.

Instead of inserting something into a plot: try planting the noun in the second noun.

Check planting something which is not a seed in something:
	instead say "That cannot be planted."
Check planting a seed in something which is not a plot:
	instead say "You cannot plant this in just any ground."
Check planting a seed in an untilled plot:
	instead say "The ground is too hard and needs to be tilled first."

Carry out planting: now the noun is in the second noun.

Report planting: say "You gently dig a small hole in [the second noun] and lovingly plant [the noun]."			

Does the player mean planting a seed in a plot: it is likely.


A Small Field is a room.				
						
The dirt patch is an untilled plot in the small field.

The player carries a tomato seed.

Test me with "till / plant".

Thank you everyone especially vyznev. Now I’m going to spend hours going over and over your code to apply it to all the other things I want done, you have just saved me a lot of time and frustration.

At part two and now I’m having trouble with randomness.

When the player performs an action I want to award him with a random amount of a specific item, in this case: When he harvests a tomato plant he recieves a random amount of tomatoes.

I’ve tried various methods with no success, any ideas?

The trouble seems to be round about here:

Seeds have a thing called harvestable fruit. The harvestable fruit of a tomato seed is a tomato.

How do I affect the amount of harvestable fruit the player would get? Putting numbers gives me this:

Problem. In the sentence ‘now the player carries two harvestable fruit of the noun’ , I was expecting to read a condition, but instead found some text that I couldn’t understand - ‘player carries two harvestable fruit of the noun’.

What would work here

Well, there’s several issue you’ll need to solve to get that to work.

First, vanilla Inform doesn’t support the dynamic creation of objects out of the box. You’ll either have to include an extension that allows it (such as Dynamic Objects by Jesse McGrew) or pre-create a sufficiently large pool of tomatoes from which the player can draw. For some example, see Chapter 10.3. “Dispensers and Supplies of Small Objects” in The Inform Recipe Book.

Second, related to the above, “now the player carries two tomatoes” is too vague an instruction for Inform to carry out during play, since you haven’t specified which tomatoes the player should carry or where they should come from. (The natural assumption here would be that Inform should just make them out of thin air, but as noted, that’s not normally possible without extensions.)

The easiest solution is probably to just use an explicit loop to place the tomatoes one by one, as in this example:

"Fresh Tomatoes" by Vyznev Xnebara

The Garden is a room.

A tomato is a kind of thing. A tomato is always edible. The description of a tomato is "Round, red and succulent."

The plural of tomato is tomatoes. There are 10 tomatoes.

[We don't want just "tomato" to be understood as the plant, hence this workaround.]
A tomato-plant is a supporter in the garden. The printed name is "tomato plant". Understand "plant" and "tomato plant" as the tomato-plant.

When play begins:
	let N be a random number between 2 and 10;
	while the number of tomatoes on the tomato-plant is less than N and there is an off-stage tomato:
		let the fruit be a random off-stage tomato;
		now the fruit is on the tomato-plant.

Test me with "x tomato plant / x tomato / eat tomato / x plant".