The short answer to the orig question is you can’t clone stuff during the game, but you can after a fashion at boot time, by making a big pile of it then, like what gil was saying.
For instance, Sean was saying you may not need real bullets. Let’s see how far we can get without them.
Say the pistol can hold 6 shots. You don’t need to make 6 actual bullets. You just give the pistol a shot capacity, and also a number recording how many shots it has left. We’ll make ‘guns’ a type of thing, and the pistol a gun.
[code]A gun is a kind of thing.
A gun has a number called capacity.
The capacity of a gun is usually 6.
A gun has a number called shots remaining.
When play begins (this is the load all guns rule):
repeat with G running through guns:
now the shots remaining of G is the capacity of G;[/code]
Now if you make a new gun, by default it has 6 shots. An exception may be the rifle, which we’ll give 8:
The rifle is a gun in the warehouse. The capacity of a rifle is 8.
Then you make a shoot/fire command. And when you fire a gun, you reduce its shots remaining by 1. So far, no real bullet objects have been used.
But the player is likely to want to say something about the bullets. (eg ‘examine bullets’) So we make them a part of every gun. This is kind of a cloning technique, because with each gun you make, it will come with a ‘bullets’ part that the player can examine.
The shells are trickier. In this case, we do need to make a supply of shells. (See recipe book 10.3 in the docs for a couple of examples. I’ve borrowed from the ‘Pizza Prince’ one.)
Putting all of the above together, I’ve made a 1 room example with two weapons (player comes armed with pistol) and two targets (15 bottles and a crate) and a basic ‘shoot’ command. To change weapons, you have to be carrying the weapon and type ‘ready (weapon)’. X a weapon to check the remaining ammo. If you’re out of ammo or not carrying a weapon, you automatically ready the one you pick up.
Things I haven’t attended to - reloading. Variations on the word bullets (eg ‘bullet’). The fact the player may want to see how much ammo they have if they ‘x bullets’. But there’s a lot here you should be able to use:
(Without reloading supported, there can only be 14 shots fired in this demo, and I made 15 shell casings in total.)
[rant][code]Warehouse is a room.
A bottle is a kind of thing. 15 bottles are in warehouse.
A crate is a fixed in place thing in warehouse.
A spent shell is a kind of thing. 15 spent shells are in bullet limbo.
A gun is a kind of thing.
A gun has a number called capacity.
The capacity of a gun is usually 6.
A gun has a number called shots remaining.
When play begins (this is the load all guns rule):
repeat with G running through guns:
now the shots remaining of G is the capacity of G;
The pistol is a gun. The player carries the pistol.
The rifle is a gun in the warehouse. The capacity of the rifle is 8.
The player has a thing called the readied weapon.
The readied weapon of the player is the pistol.
ammunition is a kind of thing. an ammunition is plural-named.
one ammunition (called its bullets) is a part of every gun.
Understand “ammo” as ammunition.
The description of pistol’s bullets is “These are small bullets.”
The description of rifle’s bullets is “These are big shells.”
Carry out examining a gun:
if shots remaining of the noun is 0:
say “It’s empty.”;
otherwise:
say “There [regarding the shots remaining of the noun][are] [shots remaining of the noun] shot[s] left.”;
rule succeeds;
Shooting at is an action applying to one thing.
Understand “shoot [something]” as shooting at.
Check shooting at:
unless the readied weapon of the player is a gun:
instead say “You haven’t readied a weapon.”;
if the shots remaining of the readied weapon of the player is 0:
instead say “Click - you’re out of ammo.”;
if the noun is not a bottle and the noun is not the crate:
instead say “No point shooting at that.”;
if the noun is a bottle and player carries the noun:
instead say “You can’t shoot a bottle you’re holding!”;
Carry out shooting at:
if the noun is a bottle:
now the noun is off-stage;
if the readied weapon of the player is a gun:
decrement shots remaining of the readied weapon of the player;
let EJECTED be a random spent shell in bullet limbo;
unless EJECTED is nothing:
now EJECTED is in the location;
Report shooting at:
if the noun is a bottle:
say "BLAM! The bottle explodes. ";
if the noun is the crate:
say "BLAOW! You put a hole in the crate. ";
say “A spent shell clatters to the floor.”;
readying is an action applying to one visible thing.
Understand “ready [thing]” as readying.
Check readying:
if noun is not a gun:
instead say “That’s not a firearm.”;
unless player carries noun:
instead say “You’re not holding it.”;
Carry out readying:
now the readied weapon of the player is the noun;
Report readying:
say “You ready the [noun].”;
Last carry out taking a gun:
if the readied weapon of the player is not a gun:
try readying the noun;
otherwise if the readied weapon of the player is a gun:
if shots remaining of the readied weapon of the player is 0:
try readying the noun;
Test me with “x pistol/x rifle/x pistol’s bullets/x rifle’s bullets/shoot bottle/look/get bottle/shoot bottle/drop bottle/shoot bottle/shoot crate/x pistol/shoot bottle/x pistol/shoot bottle/x pistol/shoot bottle/x pistol/shoot bottle/look/get rifle/shoot bottle/shoot bottle/shoot bottle/shoot bottle/look/x rifle/shoot bottle/shoot bottle/shoot bottle/shoot bottle/shoot bottle/look”.[/code][/rant]
Put the code in Inform and type ‘test me’ to run the demo.
-Wade