Duplicating objects

Hi all… first time poster. Just getting into writing with Inform 7.

So here’s my question… let’s say I’m creating a button and every time it is pushed it creates a donut. (Don’t ask).

I can make multiple donuts at the start by saying:

food is a kind of thing.
a donut is a kind of food.
in the room is 2 donuts.

BUT how do I add a NEW (3rd) donut when the button is pushed? Any ideas? Do I need to create a value (units of donuts)?

Hi!

(The inform forum is this way btw.)

Actually, yes, I’m going to ask. This is because that’s important to the solution. Maybe you don’t actually need it to create new donuts? You may be interested in reading this thread: Item generation and other misc newb questions...

I hope that’s of some help.

There are a number of different ways to handle this. The most important question here is this: What should happen if the player pushes the button e.g. 500 times? Should the game actually produce 500 donuts? Do you think it’s wise to create 500 donuts? Unless you’ve thought very long and hard about this, the answer is probably “No” since creating 500 donuts will cause lag; 5000 will probably make the game unusable. But if you’re sure that you need to allow the player to create 500 donuts, you’ll need Dynamic Objects by Jesse McGrew (furthermore, your project will need to be running on Glulx; see the settings panel to change this). In general, I strongly recommend avoiding this solution except as a last resort. Remember that creating objects behind the scenes and in a controlled fashion is quite different from creating them whenever the player hits a button.

Now that I’ve scared you, there are a few different ways to handle this without allowing the player to take 500 donuts. Two are discussed in the recipe book.

Thanks for the replies… I was going to limit it to a pretty small number but it seems like it’s easier to find another solution…!

If you’re limiting it to a small number, it’s easiest to define all of them up front, without placing them in any room, and just move one into the location whenever the button is pushed.

[code]There is room. A button is here.

A donut is a kind of thing. There are ten donuts.

Instead of pushing the button:
if a donut is off-stage:
let D be a random off-stage donut;
now D is in the location;
say “A donut appears.”;
otherwise:
say “Nothing happens.”[/code]

Awesome, thanks. I was way over-thinking it. I love Inform.

One nice thing Inform can do for you is select something by giving it a name. You can skip the “random off-stage donut” line by doing this:

[code]There is room. A button is here.

A donut is a kind of thing. There are ten donuts.

Instead of pushing the button:
if a donut (called D) is off-stage:
now D is in the location;
say “A donut appears.”;
otherwise:
say “Nothing happens.”[/code]

Ooh! :astonished: I never knew. That is nice.