Ways to make multiple objects work in Inform 7?

Hey,
I’m fairly new to Inform, and have mostly been experimenting and making basic games to try and get a grasp on the language, yet one of the things that I haven’t been able to do is make multiple objects “work”. In my case, it was when I tried to add several potions to the game, I couldn’t make a way for adding new potions of a type the already exists, or make it so that if there were several potions that drinking one doesn’t end up destroying them all ,as I replaced the drinking with some custom effects and stating “now [the potion] is nowhere”. Does anyone have a workaround of fix for this? I’ve look it up, but it seems that using multiple objects in Inform doesn’t seem to be a very common source of problems and so searching it up came up with nothing… Any ideas?

1 Like

Are you trying something like this? (Tip: posting your code will make it easier for us to find the problem.)

A potion is a kind of thing. The player carries three potions.

Instead of drinking a potion:
    say "You quaff [the noun]. It tastes delicious.";
    remove the noun from play.

I think what you want is discussed in 4.14 in the I7 guide, “Duplicates”.

[code]The Lab is a room.

A potion is a kind of thing.

Instead of drinking a potion (called the target potion):
say “Gulp! [The target potion] is all gone.”

10 potions are in the lab.[/code]

This produces the behavior:

[code]Lab
You can see ten potions here.

get potion
Taken.

drink potion
Gulp! The potion is all gone.

look
Lab
You can see nine potions here.[/code]

Oh wow, thanks. I genuinely missed that. I swear I looked all through the guide for something to solve my problem, guess I’m a bit air headed sometimes :stuck_out_tongue:

However, whilst the section helps a lot I’m still having trouble spawning in new items, as I keep getting errors stating I’m not being explicit enough, like if I have this:

[code]The lab is a room.
A potion is a kind of thing.
A button is a kind of thing.

Instead of drinking a potion:
say “You drink the potion. Nothing happens. Why is this a potion again?”;
remove the noun from play;

Instead of pushing a button:
say “A potion appears in from of you. Yay! Free potion!”;
now a potion is on the player;

There are 10 potions in the lab.[/code]

The line “now a potion is on the player;” causes a problem, despite me finding this works for singular object, how do I fix this? (If there’s a section in the manual devoted to spawning things that I missed, I’m going to kick myself ><)

All your objects need to exist from the beginning - you can’t spawn them in play (unless you’re using the extension Dynamic Objects by Jesse McGrew.) I suggest stashing them out of sight in a secret room. Then, you need to choose one potion from that out-of-sight room and move it onto your player.

Since it doesn’t matter which potion you choose (and since Inform can’t recognize “ANY POTION I DON’T CARE JUST PICK ONE”), you can use the “random” word to select the potion you want, like this.

[code]
The Lab is a room. A button is a thing in the Lab.

The Wings is a room. 10 potions are in the Wings.

Instead of pushing the button:
let the target potion be a random potion in the Wings;
if the target potion is a potion:
now the player has the target potion;
say “A potion appears in your hand. Yay! Free potion!”;
else:
say “There’s a clicking noise, but nothing exciting happens.”[/code]

The part about “if the target potion is a potion” is to protect you against running out of potions. If the target potion is not a potion, that means it’s the “nothing” object, which means there wasn’t a potion available in the Wings.

1 Like

I know people use out-of-world rooms and containers to stash items, and there’s nothing wrong with that, but I find it cleaner to not do that and use “off-stage” to refer to unused things.

let the target potion be a random off-stage potion;

Also, you can easily get rid of both the temporary variable and “random” (although again, nothing wrong with that approach either):

[code]The Lab is a room. A button is a thing in the Lab.

A potion is a kind of thing. There are 10 potions.

Instead of pushing the button:
if a potion (called the target potion) is off-stage:
now the player has the target potion;
say “A potion appears in your hand. Yay! Free potion!”;
else:
say “There’s a clicking noise, but nothing exciting happens.”
[/code]

1 Like

You know, I never considered doing it that way.

Use Juhana’s code! It’s cleaner than mine.

Do note that Juhana’s code has the side effect that any potion that’s moved off-stage for any reason (like, say, because you drank it) becomes eligible to be dispensed again. This may be what you want (in particular, it means the player can always go back to get more potions if they run out), but it’s worth keeping in mind, especially if you add any modifiable properties to your potions (which the dispenser should, presumably, reset).

1 Like