Renewable things/resources

Hi! I’m so sorry if this is a standard question; this is my first project. I’ve read through the documentation and can’t seem to figure out an answer.

I’m trying to create an item class (‘planting’) that is a renewable resource, so that the player can have some in their inventory and also it will remain in the room, but I can’t figure out how without hard coding in every different type of plant in the room. I want them to be able to take a few plants, but not infinite. What follows is my current sample. Any advice greatly appreciated. Sorry!


A thing can be a planting.

The Herb Garden is a room in the Grounds. The Herb Garden is west of the Entrance. "The herb garden is full of culinary herbs, most of which you recognize." Thyme is in the herb garden. Thyme is a planting. Rosemary is in the herb garden. Rosemary is a planting. Basil is in the herb garden. Basil is a planting. Sage is in the herb garden. Sage is a planting. Fennel is in the herb garden. Fennel is a planting. Fennel is undescribed. Marjoram is in the herb garden. Marjoram is a planting. Marjoram is undescribed. Parsley is in the herb garden. Parsley is a planting. Parsley is undescribed.

A sprig is a thing. Sprig is undescribed. Understand "herb", "plant", and "twig" as sprig. Sprig is in the herb garden.

Before taking a sprig:
	say "Which do you want?";
	stop the action;


[TO DO: this needs to be modified so you can take a plant but the plant will still be in the setting. Ideally i'd like to do this without having to hardcode each type of plant individually.]

Bouquet is a number that varies. Bouquet is 0.

Before taking a planting:
	if Bouquet is 0:
		say "They won't miss a few sprigs will they?";
		increment Bouquet;
		continue the action;
	otherwise if Bouquet is 1:
		say "This will add to the little bouquet.";
		increment Bouquet;
		continue the action;
	otherwise if Bouquet is greater than 1:
		say "They might actually notice you stealing the plants. Maybe if you get rid of some?";
		stop the action;
		
Before dropping a planting:
	Decrement Bouquet;
	continue the action;
6 Likes

Hi Claire, and welcome. No need to be sorry – helping people with these kinds of challenges is what this bit of the forum is about.

I was thinking ‘I’ll quickly sort this out before watching another episode of Survivor.’ Then I realised what you’re after is, well, it requires a bit of doing! Mostly the part where you want the plants to be in both the garden and the inventory. I had everything else coded up, and though you expressed a desire to avoid hardcoding, I don’t think there’s a way around this bit… you’re going to need to create at least a pair of each plant, one for the inventory and one for the garden, or two sets of plants, an ‘evergreen’ version, that stays in the garden, and one that goes into the inventory. And it probably needs relations, or a table…

I think the evergreen solution is better because then you can easily distinguish between the two. This may head off problems nobody’s even though of yet further down the road.

I’ve started this code and will be back in a couple of hours to post and describe. I may end up being passed while I’m away, but frankly I’ll be interested to get my solution working in any case.

-Wade

5 Likes

I’m not sure that this avoids the “hardcoding” that you mentioned, but here’s a sample implementation:

Version with individual herb plantings
"Garden"

An herb is a kind of value. Some herbs are thyme, rosemary, basil, sage, fennel, marjoram and parsley.

A plant is a kind of thing. A plant is usually fixed in place. A plant has an herb called species. The printed name of a plant is usually "planting of [species of the item described]". The printed plural name of a plant is usually "plantings of [species of the item described]".

The verb to be sprouted from means the species property.

Definition: a sprig is matching if the herb of it is the species of the item described.

Understand the species property as describing a plant.

The Grounds is a region.

The Herb Garden is a room in the Grounds. The Herb Garden is west of the Entrance. “The herb garden is full of culinary herbs, most of which you recognize."

There is a plant. It is sprouted from thyme.
There is a plant. It is sprouted from rosemary.
There is a plant. It is sprouted from basil.
There is a plant. It is sprouted from sage.
There is a plant. It is sprouted from fennel. It is undescribed.
There is a  plant. It is sprouted from marjoram. It is undescribed.
There is a  plant. It is sprouted from parsley. It is undescribed.
Every plant is in the Garden.

A sprig is a kind of thing. A sprig has an herb. The printed name of a sprig is usually "sprig of [herb]". The printed plural name of a sprig is usually "sprigs of [herb]".

Understand the herb property as describing a sprig.

Understand “herb” and “twig” as a sprig.

Three sprigs are part of every plant.

Does the player mean taking a plant: it is unlikely.
Does the player mean taking a sprig: it is likely.

When play begins:
	repeat with bit running through sprigs:
		now the herb of bit is the species of a random plant incorporating bit.

Instead of taking a plant when the noun incorporates a sprig:
	try taking a random sprig part of the noun.

First Check taking a sprig part of a plant:
	let source be the holder of the noun;
	now the noun is in the holder of source;
	try taking the noun;
	unless the noun is carried by the player:
		now the noun is part of source;
		rule fails;
	otherwise:
		rule succeeds.  

Check taking a sprig when the player carries no sprigs:
	say “They won’t miss a few sprigs will they?”;
	continue the action.

Check taking a sprig when the player carries exactly one sprig:
	say “This will add to the little bouquet.”;
	continue the action.

Check taking a sprig when the player carries at least two sprigs:
	say “They might actually notice you stealing the plants. Maybe if you get rid of some?” instead.

Before listing contents:
	group sprigs together.

Rule for printing the name of a sprig while listing contents:
	if the listing group size is at least two:
		say "[herb]";
	otherwise:
		say "sprig of [herb]".

Before grouping together sprigs:
	say "sprigs of ".

Rule for clarifying the parser's choice of a plant while taking:
	say "(a sprig from [the item described])[command clarification break]".

Definition: a plant is noun-matching if the noun is a sprig and the species of it is the herb of the noun.

After dropping a sprig:
	let source be a random noun-matching plant;
	now the noun is part of source;
	say "You cast away the sprig, which is quickly lost in the greenery."

If any part of this doesn’t suit your purposes, then providing more details about what you want to accomplish would be helpful.

EDIT: Maybe this is closer to what you meant: The plantings are treated as a mass noun.

"Garden II-B"

[A kind of value is different from a kind of thing, but there are many features of Inform that allow them to be used fruitfully in conjunction with things. See WWI 4.5 "Kinds of value" to start.]

An herb is a kind of value. Some herbs are thyme, rosemary, basil, sage, fennel, marjoram and parsley.

[Properties can be applied to kinds of value. See WWI 4.7 "New either/or properties" for this type.]

An herb can be hidden or discovered. Fennel, marjoram and parsley are hidden.

The Grounds is a region.

The Herb Garden is a room in the Grounds. The Herb Garden is west of the Entrance. “The herb garden is full of culinary herbs, most of which you recognize."

[You seem to want to imply various plantings being present, so this lists the "discovered" herbs in the printed name of the mass plantings. See WWI 21.3 Saying lists of values.

The Understand... statement makes it so that the name of any herb will be interpreted as the plantings object. See WWI 17.11 "Understanding values" for more.]

Some plantings are in the Herb Garden. The printed name of the plantings is "plantings of [list of discovered herbs]". Understand "[herb]" as the plantings.

[Sprigs are set up as generic objects whose name and description depend on an assigned herb property. This example uses a "nameless" herb property. See WWI 4.9 Using new kinds of value in properties.]

A sprig is a kind of thing. A sprig has an herb. The printed name of a sprig is usually "sprig of [herb]". The printed plural name of a sprig is usually "sprigs of [herb]".

[This Understand... statement is one of the main motivations for setting up herbs as a kind of value. See WWI 17.15 "Understanding things by their properties" for details.]

Understand the herb property as describing a sprig.

Understand “herb” and “twig” as a sprig.

[This just asserts five "blank" sprigs into existence. They actually start out as sprigs of thyme because thyme is the default value of herb. See WWI 4.11 "Default values of kinds".] 

There are five sprigs.

[Because the name of an herb can be understood as both the plantings object or a sprig, this activity rule is useful to preserve the illusion of individual plantings when automatic disambiguation occurs. See WWI 18.30 "Clarifying the parser's choice of something".]

Rule for clarifying the parser's choice of the plantings:
	say "(a sprig from the [herb understood] planting)[command clarification break]".

[Deciding which action-processing rulebook to use is something of a stylistic choice. The "before" rulebook is so early that some basic world-model checks are skipped, so in this case an "instead" rule seemed better. See  WWI 12.2 "How actions are processed" for some guidance.

This rule is the meat of the illusion: When the player tries to pick the planting, an off-stage sprig is summoned and assigned an herb type matching the herb name used in the player's command. See WWI 17.19 "Understanding kinds of value" for the brief note on the powerful "<kind> understood" phrase.]

Instead of taking the plantings when at least one sprig (called new picking) is off-stage:
	now the herb of new picking is the herb understood;
	now new picking is in the holder of the plantings;
	try taking new picking;
	if the player carries new picking, rule succeeds;
	otherwise now new picking is off-stage.

[Since these only make sense to display when the action is happening, they're implemented as "carry out" rules. The use of "first" means that they would happen in front of any applicable Standard Rules, important in this case because those Standard Rules will change the number of sprigs carried by the player. See WWi 19.7 "The preamble of a rule".]

First carry out taking a sprig when the player carries no sprigs:
	say “They won’t miss a few sprigs will they?”

First carry out taking a sprig when the player carries exactly one sprig:
	say “This will add to the little bouquet.”

[Since this one makes sense when the action is being disallowed, the traditional placement is in a "check" rulebook. Note that, although "check" rules are frequently employed to stop actions, they do not stop the action by default. It's necessary to request that explicitly with "stop the action" or similar -- in this case the "instead" keyword is used. See WWI 19.11 "Success and failure" and the general index entry on "stop the action".]

Check taking a sprig when the player carries at least two sprigs:
	say “They might actually notice you stealing the plants. Maybe if you get rid of some?” instead.

[These next items are purely for stylistic purposes -- making it easy to imitate the Emily Short style. See 18.14 "Grouping something together". Note that the "listing group size" variable is not documented except for its appearance in the Standard Rules.]

Before listing contents:
	group sprigs together.

Rule for printing the name of a sprig while listing contents:
	if the listing group size is at least two:
		say "[herb]";
	otherwise:
		say "sprig of [herb]".

Before grouping together sprigs:
	say "sprigs of ".

[This every turn rule is necessary to reset it every turn to prevent a situation in which dropping one herb after carrying two leaves the printed name of the one in inventory as just the herb name. Placement in this rulebook means that it will only happen after action-processing is finished. See WWI 9.5 "Every turn".]

Every turn:
	now listing group size is one.

[You didn't have anything like this in your original attempt, but if you want recyclable items it's necessary to recycle them. An "after" rule is used to preclude the normal dropping report. See WWI 7.5 "After rules".]

After dropping a sprig:
	now the noun is off-stage;
	say "You cast away the sprig, which is quickly lost in the greenery."

Rule for clarifying the parser's choice of a carried sprig:
	do nothing.

[It wasn't really clear just why some were declared as undescribed, but this rule acknowledges the player's discovery in future room descriptions. A "before" rule is deliberately chosen because it seems fair that this should happen even if the action ultimately fails. For details on the powerful "(called... )" syntax, see WWI 8.15 "Calling names".]

Before taking a sprig when the herb of the noun is a hidden herb (called new seasoning):
	now new seasoning is discovered.

[These use a non-beginner technique to handle attempts to take the plantings directly. The use of "first" for the "instead" rule puts it ahead of the other "instead" rule above.] 

To decide which herb is no herb at all:
	(- nothing -).

First Instead of taking the plantings when the herb understood is no herb at all:
	say "There are so many choices! Perhaps you should select just one at a time."

[This is to prevent the most likely phrasing of attempts to take more than one herb at a time. See WWI 18.33 "Reading a command" for details.]

After reading a command when the player's command includes "and [herb]":
	say "You don't want to get caught. Maybe start with just one.";
	reject the player's command.

EDIT 2: I’ve added some explanatory comments with citations to documentation for each section of the “mass plantings” version. I’ve also made some tweaks and added some new code, in particular one change to prevent >TAKE PLANTINGS as a command from generating a run-time problem because no herb name is used in the command, and another change to fix an issue with the inventory display.

One thing to note about the “mass plantings” version is that the illusion might work so well as to prompt an experienced player to try combining actions with a command like >TAKE BASIL AND THYME. This will parse, but probably not as desired… the illusion is not preserved, and the effect is that only the last herb name used will be retrieved. Another new rule was added to prevent the worst effects, but it is still possible to craft commands that won’t work correctly, such as >TAKE FENNEL, SAGE.

5 Likes

Can you run this code? I can’t compile the source in the most up to date Inform. I get weirdo errors like " There is an undescribed plant’ appears to say two things are the same - I am reading ‘’ and ‘’ as two different things"

-Wade

3 Likes

Yes… in 6M62. I forgot that the rules on declarations were changed a little for 10.1. Lines updated for compatibility.

There is a plant. It is sprouted from fennel. It is undescribed.
There is a plant. It is sprouted from marjoram. It is undescribed.
There is a plant. It is sprouted from parsley. It is undescribed.
4 Likes

Okay, I’ve got my version of this thing ready :slight_smile:

It’s in the Summary section:

Summary
"The Garden Of Lax Terminolgy"

bouquet-size is initially 0.

A plant is a kind of thing.

A source-plant is a kind of plant. An source-plant is usually fixed in place.
A source-plant has a number called bouquet-count. The bouquet-count of a source-plant is 0.

A dupe-plant is a kind of plant.


The Herb Garden is a room. The Herb Garden is west of the Entrance. "The herb garden is full of culinary herbs, most of which you recognize."

lab is east of herb garden.

Thyme is a source-plant in the herb garden.
Rosemary is a source-plant in the herb garden.
Basil is a source-plant in the herb garden.
Sage is a source-plant in the herb garden.
Fennel is a source-plant in the herb garden. Fennel is undescribed.
Marjoram is a source-plant in the herb garden. Marjoram is undescribed.
Parsley is a source-plant in the herb garden. Parsley is undescribed.

dp-Thyme is a dupe-plant. The printed name is "Thyme". Understand "thyme" as dp-Thyme.
dp-Rosemary is a dupe-plant. The printed name is "Rosemary". Understand "rosemary" as dp-Rosemary.
dp-Basil is a dupe-plant. The printed name is "Basil". Understand "basil" as dp-Basil.
dp-Sage is a dupe-plant. The printed name is "Sage". Understand "sage" as dp-Sage.
dp-Fennel is a dupe-plant. The printed name is "Fennel". dp-Fennel is undescribed. Understand "fennel" as dp-Fennel.
dp-Marjoram is a dupe-plant. The printed name is "Marjoram". dp-Marjoram is undescribed. Understand "marjoram" as dp-Marjoram.
dp-Parsley is a dupe-plant. The printed name is "Parsley". dp-Parsley is undescribed. Understand "parsley" as dp-parsley

Kinship relates plants to each other.

The verb to kin means the kinship relation.

Thyme kins dp-Thyme.
Rosemary kins dp-Rosemary.
Basil kins dp-Basil.
Sage kins dp-Sage.
Fennel kins dp-Fennel.
Marjoram kins dp-Marjoram.
Parsley kins dp-Parsley.

A sprig is a thing. Sprig is undescribed. Understand "herb", "plant", and "twig" as sprig. Sprig is in the herb garden.

To decide what thing is the kindred of (P - a plant):
	let Z be a random plant that kins P;
	decide on Z;

Instead of taking a source-plant:
	if bouquet-size is 3:
		instead say "They might actually notice you stealing the plants. Maybe if you get rid of some?";
	increment bouquet-size;
	let Z be kindred of noun;
	unless player holds Z:
		now player holds Z;
	increment bouquet-count of the noun;
	if bouquet-size is:
		-- 1: say "They won't miss a few sprigs will they?";
		-- 2: say "This will add to the little bouquet.";
		-- 3: say "The bouquet's looking good, now.";

Instead of dropping a dupe-plant:
	decrement bouquet-size;
	let Z be kindred of noun;
	decrement bouquet-count of Z;
	if bouquet-count of Z is 0:
		now noun is nowhere;
		say "You drop your last sprig of [noun]. ";
	otherwise:
		say "You drop a sprig of [noun]. ";
	say "It's gone.";

Before taking a sprig:
	say "Which do you want?";
	stop the action;

After printing the name of a dupe-plant while taking inventory:
	say " ([bouquet-count of (kindred of item described)])";

Test me with "get sage/get rosemary/get thyme/i/get sage/drop sage/get thyme/i/drop thyme/drop thyme".

I’ve got some comments on your original code first, @darling58 .

I think technically, your line ‘a thing can be a planting’ creates an adjective applicable to things called ‘a planting’. Like saying ‘a thing can be openable’. What would serve you better is making plants a kind of thing - ‘A plant is a kind of thing.’

You’ve gone with a ‘before’ rule for the taking of the plantings. This is a possible choice. The challenge of your whole mechanism is that the taking you’re doing is not standard. We’re not removing the thing from the room and putting it in our inventory, which is the normal mechanism. You’re going to replace that mechanism with something custom. So an ‘Instead of’ rule might be more appropriate here.

e.g. Instead of taking a planting:

In the case of this simple example, there won’t be any real difference.

To my own code – so I’ve created a kind called plant. Then a subkind of plant called an source-plant. These are like the herb generators that sit in the room. When you try take one, the code puts a ‘dupe-plant’ of the same species into your inventory, another kind I made. And it totes up that you’ve got one more of that species. I also added a bit that, when you type inventory, shows how many of each herb you’ve got in your inventory. And the total carriable herb limit is still 3, as in your original example. Dropping a herb reduces your count of that species, and if you throw away your last one, your dupe-plant disappears from your inventory, too.

I defined relations (docs chapter 13) to make the connection between the source-plants and dupe plants. Probably clumsily – I hardly ever use relations. And all the source-plant and dupe-plant data has been tediously copy-pasted out by me. There are ways to use tables to define the same data less tediously. However I just wanted to try to keep things transparentish, since it’s your first post. I hope this is all useful.

-Wade

4 Likes

Thank you @severedhand @otistdog !!! And thank you for the advice on adj, kinds, rules, etc. If you have any recommendations on projects / code bases that are good to consult in addition to the main documentation and examples, I’d appreciate it. There’s a lot to learn!

Hope Survivor was fun :slight_smile:

3 Likes

(Super off-topic, but I gotta ask. Survivor as in the reality TV show or Survivors as in the excellent British Television Series, or even the failed yet good reboot?)

1 Like

The post Inform 7 documentation and resources has links to additional documentation material and to source code examples. And of course, don’t hesitate to ask questions here. :slight_smile:

3 Likes

Apologies for adding on to a solved topic, but I’m running into an interesting error. I’ve made a basic test script, and for some reason, sometimes, the output includes a parenthetical list of plants instead of the sprig parenthetical. This happens even when I comment out the (a sprig from) lines, so I’m not sure where it’s coming from? Any advice appreciated.

Test picking with "pick herb / take plant / take thyme / pick basil / pick thyme / drop marjoram / look / drop basil / pick marjoram".

An herb is a kind of value. Some herbs are thyme, rosemary, basil, sage, fennel, marjoram and parsley.

An herb can be hidden or discovered. Fennel, marjoram and parsley are hidden.

The Herb Garden is a room in the Grounds. The Herb Garden is west of the Entrance. “The herb garden is full of culinary herbs, most of which you recognize." There is a small rock in the Herb Garden. Understand "small" and "rock" as the small rock.

Some plantings are in the Herb Garden. The printed name of the plantings is "plantings of [list of discovered herbs]". Understand "[herb]" as the plantings.

A spriglet is a thing. Spriglet is undescribed. Understand "herb", "plant", and "twig" as spriglet. Spriglet is in the herb garden.

Before taking a spriglet:
	say "Which do you want?";
	stop the action;

A sprig is a kind of thing. A sprig has an herb. The printed name of a sprig is usually "sprig of [herb]". The printed plural name of a sprig is usually "sprigs of [herb]".

Understand the herb property as describing a sprig. 

Understand "pick [something]" as taking. [buggy - this needs to be updated to be specific to only plants - TO DO 'flora' adj.]

There are five sprigs.
	
Instead of taking the plantings when at least one sprig (called new picking) is off-stage:
	now the herb of new picking is the herb understood;
	now new picking is in the holder of the plantings	;
	try taking new picking;
	if the player carries new picking, rule succeeds;
	otherwise now new picking is off-stage.

Before dropping a sprig:
	if the herb of the noun is a hidden herb (called new seasoning):
		now new seasoning is discovered; [to do: this still doesn't work]

Check taking a sprig when the player carries no sprigs:
	[say "(a sprig from the [herb understood] planting)[command clarification break]";]
	say “They won’t miss a few sprigs will they?”

Check taking a sprig when the player carries exactly one sprig:
	[say "(a sprig from the [herb understood] planting)[command clarification break]";]
	say “This will add to the little bouquet.”

Instead of taking a sprig when the player carries at least two sprigs:
	say “They might actually notice you stealing the plants. Maybe if you get rid of some?”;
	
Before listing contents:
	group sprigs together.

Rule for printing the name of a sprig while listing contents:
	if the listing group size is at least two:
		say "[herb]";
	otherwise:
		say "sprig of [herb]".

Before grouping together sprigs:
	say "sprigs of ".

After dropping a sprig:
	now the noun is off-stage;
	say "You cast away the sprig, which is quickly lost in the greenery."

Before taking a sprig when the herb of the noun is a hidden herb (called new seasoning):
	now new seasoning is discovered.
2 Likes

I’m not sure which behavior you want to avoid, so here are some possibilities:

if you don’t want to be able to pick herbs before you discover them, you can change the line to this:
Understand "[discovered herb]" as the plantings.

If you want it to automatically pay attention to the sprigs more than the plantings:

Does the player mean doing anything to the plantings:
	it is unlikely;

If you don’t want it to list every planting when it puts them in parentheses:
Rule for clarifying the parser's choice of the plantings: say "(the plantings)"

Or is it a different behavior you want to change? And this all looks pretty cool btw!

3 Likes

This is from an automatic process called “disambiguation,” which happens when the player’s command uses a word that can refer to more than one thing. The parser produces a message to clarify which object it thought the player meant, based on internal scoring logic. That scoring can be affected by does the player mean rules.

What you’re seeing is the default printed name of the plantings object in that automatically-produced message. Mathbrush pointed out a way to address it, and the updated code I just posted has a rule added that is similar to his example (but which may not be as useful because it counts on herb understood being defined).

EDIT: You may also have been referring to the response to >DROP MARJORAM (a hidden herb) before the PC has any marjoram. In this case, the Understand "[herb]" as the plantings. line is matching the word “marjoram” to the plantings because that’s the only object present that can match the word. (There are no sprigs of marjoram to start.) The response is the parser complaining that the object to be dropped is not actually held by the player.

I wasn’t certain about what you were trying to do by listing some herbs as undescribed in your original code. Hiding something via undescribed is a weak form of hiding in that it is an instruction not to mention the item in the room description but otherwise does nothing to obscure the item’s presence. Items “hidden” this way are prone to accidental discovery via commands such as >TAKE ALL or by being listed in “Which do you mean…?” questions. My assumption was that you chose it because you wanted a player to be able to try >TAKE MARJORAM right away and have the command work.

With the modification to the Understand... line suggested by Mathbrush, only discovered herbs can be used to interact with the plantings. However, that means that the player can’t pick any of the hidden herbs until something else happens to make those herbs discovered. It’s a stronger form of hiding. (Well, really pseudo-hiding, since no herb objects are actually there in the first place.)

3 Likes

Hehe, yes American Survivor. I’m catching up on a recent season I missed when it was new. I’ve watched the American one from the beginning, 40+ seasons ago. There have been about nine seasons of Australian Survivor, three of New Zealand and eight of South Africa. South Africa’s been the most interesting, culturally (I mean re: modern South Africa, not the countries they visit – ALL Survivors have basically stopped going anywhere except Fiji!)

-Wade

1 Like

Really!? Wow… wasn’t that one of the draws early on? Every season somewhere new and challenging?

I’ll just let all you herb gardeners in this topic know I’ve taken the Survivor discussion to PM :slight_smile:

-Wade

1 Like