Trying to make a relation between an object and a kind?

Not sure if I’m on the right path with this, but here’s what I’m trying to do:

I’m making a simulation of a “token cup,” where there is a container stocked with a bunch of different tokens, and an action can be taken to draw a random token from the cup and show what it is.

It works through simple built-in inform mechanics: there’s a shelf, and if you put the iron figurine on the shelf, then two iron tokens will appear in the cup, and if you put the quartz figurine on the shelf, ten quartz tokens appear, etc.

This part all works fine. What I’m trying to do now is make a way to label the figurines, and with that same action, name all of the associated tokens.

I have this code (borrowed from the Inform manual) for labeling the figurines:

Labeling it with is an action applying to one thing and one topic. Understand "label [something] [text]" as labeling it with.

Instead of labeling a figurine with something:
	let N be "[the topic understood]";
	replace the text "'" in N with "";
	now the label of the noun is "[N]";
	say "Okay, now [the noun] is labelled '[N].'"

A figurine is a kind of thing I’ve set up. So is a token. What I can’t figure out is how to make a relation between all the tokens and their matching figurine, and then add code so that when the figurine is labeled, so are all its tokens. (There are from two to forty tokens of each various type.)

Does this sound like a reasonable way to do this? And if so, any ideas on how to get it working?

Hi Caleb,

I’m afraid I don’t quite understand what you’re looking for. This seems pretty straightforward if you have iron tokens and quartz tokens. Are you saying that the tokens and figurines all start out “undefined” and gain their property (such as its material) at runtime – i.e. due to something that happens during the game itself?

Maybe you could post an example of what a game transcript would look like?

The thing I’m having trouble with is the naming: what I can’t figure out at heart is how to rename a bunch of identical things (the tokens) all at once.

So the transcript would be something like:

PUT IRON FIGURINE ON SHELF
You place the iron figurine on the shelf. Two iron tokens appear in the token cup.

EXAMINE IRON TOKEN
The iron token represents nothing.

LABEL IRON FIGURINE LOBB
Okay, now the iron figurine is named “Lobb”.

EXAMINE IRON TOKEN
The iron token represents Lobb.

PRESS BUTTON
A random token flies out of the cup: an iron token, representing Lobb.


What’s tripping me up is that there are multiples of each token. I need to rename all of them at once when I rename each figurine, if possible. Here’s how I’m defining the figurines and tokens so far:

A figurine is a kind of thing.

An iron figurine is in the storage chest. It has some text called the label. The label of it is "nothing". It is a figurine.

A token is a kind of thing. It has some text called the label. The label of it is usually "nothing".

An iron token is a kind of token.

Two iron tokens are in Limbo.

Setting a property on a bunch of things is possible, just a bit tricky. You have to define a new sentence verb:

A token is a kind of thing.
A token has some text called the label. The label of it is usually "nothing".

The verb to label-show means the label property.

Carry out labelling [...]:
	now all iron tokens label-show "Foo.";

There are other ways to do this. For example, you could set things up so every token has a figurine (via a relation or property). Then, rather than giving each token a label, you could rely on the label of the figurine of the token.

This is what I was trying to do originally, so maybe I was going down the wrong path with giving all the tokens their own label!

I had tried to make a relation between each figurine and all its matching tokens, something like this:

Signifying relates various things to one thing (called the signifier).

The verb to signify means the signifying relation.

The iron token signifies the iron figurine.

After examining a token:
	say "It refers to [label of signifier of noun]."

That way I thought I’d only need labels on the figurines, and the tokens would all just refer to the labels of their related figurines. I couldn’t figure out how to make the relation between kinds and objects, though.

I think I got it! Simple as an “All iron tokens refer to the iron figurine” line slipped into When Play Begins.

Thanks for pointing me back in the right direction.

2 Likes

So that sounds good… but it also sounds like you could implement iron, quartz, etc. as a kind of value, give tokens and figurines properties with that value, and then then define a relation between them based on whether they share that property–maybe that would automate things even more?

Something like:

A composition is a kind of value. The compositions are iron, quartz, marble, basalt, copper, and wood.

A figurine is a kind of thing. A figurine has a composition. Understand the composition property as describing a figurine. Before printing the name of a figurine: say "[composition] ".
A figurine has some text called the label.

A token is a kind of thing. A token has a composition. Understand the composition property as describing a token. Before printing the name of a token: say "[composition] ". 
Before printing the plural name of a token: say "[composition] ".

Signification relates a token (called X) to a figurine (called Y) when the composition of X is the composition of Y. The verb to signify means the signification relation. 

Instead of examining a token:
	if the token signifies a figurine (called the archetype) and the label of the archetype is not "":
		say "It represents [label of the archetype].";
	otherwise:
		say "It represents nothing."

The player carries two iron tokens.

Lab is a room. A storage chest is a container in Lab.
[everything below here is copied from your code]
One iron figurine is in the storage chest. 

Labeling it with is an action applying to one thing and one topic. Understand "label [something] [text]" as labeling it with.

Instead of labeling a figurine with something:
	let N be "[the topic understood]";
	replace the text "'" in N with "";
	now the label of the noun is "[N]";
	say "Okay, now [the noun] is labelled '[N].'"

EDIT TO ADD: This could also let you define the composition of tokens on the fly; keep a supply of blank tokens in Limbo, and when you put a figurine on the shelf, you could move some tokens from Limbo and redefine their composition to match the figurine.

3 Likes

Ah, excellent! That makes things more elegant for sure. I didn’t quite realize how to use values but this is a great template. Thank you!