Coding a snowball fight

Hello all,

Thank you everyone for all the help I’ve received so far. My first story (which is going to be for Christmas) is coming along nicely.

Having said that, I’m at a point where I’m a bit stuck, and could use some code examples to help me along again.

Here’s what I’m trying to do:

My character comes to an IcePond full of elves who are about to have a snowball fight. When he arrives, an elf hands him a bag with 100 snowballs. Here’s the code I’ve come up with for that (which only partially works):

[code]
understand the command “throw” as something new.
throwing is an action applying to one thing.
understand “fling [things]” as throwing.
understand “chuck [things]” as throwing.
understand “heave [things]” as throwing.
understand “throw [things]” as throwing.
understand “toss [things]” as throwing.
understand “hurl [things]” as throwing.
understand “pitch [things]” as throwing.
understand “fling [something] at [something]” as throwing it at.
understand “throw [something] at [something]” as throwing it at.
understand “chuck [things] at[something]” as throwing it at.
understand “heave [things] at [something]” as throwing it at.
understand “throw [things] at [something]” as throwing it at.
understand “toss [things] at [something]” as throwing it at.
understand “hurl [things] at[something]” as throwing it at.
understand “pitch [things] at [something]” as throwing it at.

A snowball is a thing.

A snowballbag is a container. The printed name of snowballbag is “Bag of Snowballs”.

A snowballbag is here. There are 100 snowballs inside the snowballbag.

After going to IcePond for the first time:
say “The largest elf hands you a small bag that is much heavier than it should be.”;
now the player has the snowballbag;
continue the action.[/code]

With the above code, the player does indeed get the snowball bag, but the text telling them they were handed it does not print for some reason.

Now for my second question - how do I do the following:

  1. Subtract one snowball from the snowball bag everytime the player types “throw snowball”?
  2. Provide a random result “i.e. you hit an elf in the [X]”, or you “you missed completely!” based on a 50/50 hit/miss chance?
  3. Keep track of those results so when the player achieves a certain amount of hits, another action happens (specifically, one of the elves drops an object).

Thanks again, folks - I’m really learning alot with your help :wink:

If the player can’t do other things with the snowballs, it might be better to have only a single “snowball” object and give the bag a variable to determine how many are left.

There is a container called a small bag. The bag has a number called snowball count. The snowball count of the bag is 100.
In the small bag is a snowball.

Instead of throwing the snowball:
    if a random chance of 1 in 2 succeeds:
        [hit]
    otherwise:
        [miss]
    move the snowball to the small bag;
    decrement the snowball count of the bag.

After going to the icy pond when the player does not carry the small bag:
    say [stuff];
    now the player has the small bag.

You can set up verb-level synonyms, which makes your code more compact:

Understand the command "throw" as something new.
Throwing is an action applying to one thing.
Understand "throw [things]" as throwing.
Understand "throw [things] at [something]" as throwing it at.
Understand the commands "pitch", "toss", "hurl", "heave", "chuck" as "throw".

The above code produces errors.

You need to put your own code in place of [hit], [miss], etc.