# Does Inform 7 inherently avoid duplicate things?

I’ll up front my question, and then let the description and code follow.

When I’m using a rule that brings things into play, from offstage, I guess, does it avoid avoid duplicates? Is off-stage the answer? Once it’s ‘taken,’ it can’t be taken again?

Does the same apply if I were building things with tables? (I.e. randomized names and such?)

This is a lot of code, but I figure it’s all necessary to explain my question!

Basically, I’ve got a rule generating a number, and then another rule using that number as the framework for probabilities on choosing certain kinds of things.

The prototype version of what I’m trying to build is using ‘nerd and jock’ schoolyard archetypes as an easy reference.

``````This is the random-ideology rule:
now ideology is a random number between 1 and 3;
If a random chance of 1 in 2 succeeds:
now ideology is ideology plus 7;
say "Ideology is [ideology]."

This is the fill-locker rule:
If a random chance of ideology in 11 succeeds:
say "jock succeeds ";
if a random chance of 7 in 10 succeeds:
Let new-evidence be a random jockish evidence;
say "- jockish evidence ";
say "[new-evidence]";
now new-evidence is in locker;
otherwise:
Let new-evidence be a random ambiguous evidence;
say "- ambiguous jock evidence ";
say "[new-evidence]";
now new-evidence is in locker;
otherwise:
say "nerd succeeds ";
if a random chance of 7 in 10 succeeds:
Let new-evidence be a random nerdy evidence;
say "- nerdy evidence ";
say "[new-evidence]";
now new-evidence is in locker;
otherwise:
Let new-evidence be a random ambiguous evidence;
say "- ambiguous nerd evidence ";
say "[new-evidence]";
now new-evidence is in locker.

Volume 2 - Scenario

Use scoring.

Book 1 - Declarations

Evidence is a kind of thing. Evidence can be nerdy, jockish, or ambiguous.

A binder is a kind of evidence.

A notebook is a kind of evidence.

A backpack is a kind of evidence.

A lunchbox is a kind of evidence.

[here is where I start listing different kinds of things, the first one as an example but I trimmed out the rest for length]

The Star Wars binder is a nerdy binder. The description of the Star Wars binder is "It has a sticker that says 'may the force be with you' on it."

[more things follow, nerdy, jockish, and ambigous, and of binders, notebooks, backpacks, etc.]

When play begins:
abide by the random-ideology rule.

When play begins:
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule;
abide by the fill-locker rule.

``````

Inform will do exactly what you ask of it – e.g.,

``````Let new-evidence be a random jockish evidence;
``````

will grab any jockish evidence, whether or not it’s been used before.

Is that the gist of your question?

EDIT:
You might try:

``````Let new-evidence be a random off-stage jockish evidence;
``````

if you want not to use the same thing twice.

1 Like

Yup – this is exactly what I’ve done when implementing similar things. I suppose you could also define a custom property, but for the simple case you’re outlining here this will work.

I didn’t word my original question properly. In terms of the behaviour I’m seeing, so far it’s already not duplicating anything.

What I’m trying to figure out is if that is automatic; if it’s already in the built-in extensions or rules of Inform 7 to keep from duplicating things.

When I run the code I currently have it ‘saying’ things so I can see the results of the code immediately. So here’s a recent example:

Ideology is 10.

jock succeeds - ambiguous jock evidence Orange lunchbox
jock succeeds - ambiguous jock evidence Powerpuff binder
jock succeeds - ambiguous jock evidence Green binder
jock succeeds - jockish evidence Baseball binder
jock succeeds - jockish evidence Football backpack
jock succeeds - ambiguous jock evidence Powerpuff binder
jock succeeds - ambiguous jock evidence Powerpuff binder
jock succeeds - jockish evidence Baseball binder

But when I open the locker:

>open locker
You open the locker, revealing two blue pens, two yellow pens, two indigo pens, a Baseball binder, a Powerpuff binder, a Football backpack, a Green binder and an Orange lunchbox.

The code ‘generated’ the Powerpuff binder 3 times, but only one is in the locker.

No.

That’s because your code is not “generating” new binders, assuming the Powerpuff Girls one is defined the same way the Star Wars one is in the code you’ve posted above; there’s only one, so each time it’s picked it’s just being moved into the locker, and since it’s already there after the first time the two additional ones don’t actually do anything.

Creating new objects after the game has been compiled is quite tricky – there’s a Dynamic Objects extension, but unless you have a very specific need for it, it’s usually better just to create multiple instances of a kind off-stage and then move additional ones on as needed. So you could say “a Powerpuff Girls binder is a kind of binder” and them put five or however many of them off-stage so you’ve got as many as you need (I’d think unique pieces of evidence would be more interesting than duplicates, though, so that would possibly be more work for a worse outcome).

2 Likes

Right. I’m confusing the code I’ve got doing the selecting as generating. The code I’ve got ‘selected’ the Powerpuff binder three times, but there’s only one of them actually described, so it can’t be selected more than once.

I do actually have an off stage group of pens that have a colour assigned to them when they get put into the locker, and that has shown duplicates. In the example I posted above, it does show pairs of pens of different colours.

Which, I suppose if I’d been focused on the pens, it would have answered my initial question of duplicates!

To anyone finding this later… sometimes you can’t avoid dumb questions!

To your point about unique pieces of evidence… that is the current idea. I’ve been debating between fully hand-written lists of evidence things and doing some text substitution to increase the range of possibility. (Though it may also create the possibility of duplicates!)

Since the school-locker setup is meant for prototyping, I’ve also thought about doing some text substitution to make it easier to shift it into different thematic modes… tables of nerdy and jockish names and such, which then I can redo into some other kind of evidence-spectrum concept!

2 Likes

I actually learn a lot from the questions people ask, so thank you!