implementing score properly

So I’m trying to implement scoring into my game, but am having some trouble. Here is a paraphrase of the source code I have so far:

[code]Use scoring.

Place is a room.

A bucket is a container in place.

A fish is in place.

A freezer is an openable container in Place.
An ice cube is in the freezer.

After inserting the cube into the bucket:
say “You put the cube into the bucket.”
The cube melts in 3 turns from now.

At the time when the cube melts:
say “The ice cube has melted.”;
now the printed name of the cube is “water”.

After inserting the fish into the bucket for the first time:
say “You put the fish into the bucket.”;
if the printed name of the cube is “water”:
say “It’s no longer a fish out of water.”;
increase the score by 5.[/code]

So, if the actions are done in the proper order (put the cube in the bucket, wait for it to melt, then put the fish in the bucket), the score gets counted. However, if the player were to do it in a different order – like putting the fish in first or putting the fish in after the cube but not waiting for it to melt – the score will not get counted.

How can I rewrite this so that the points are implemented no matter what, as long as the fish is in the bucket with a melted cube?

Thanks!

There are various ways to handle this. Generally you’d define a property or variable which represents whether the points have been scored. Perhaps:

A thing can be scored.

After inserting the fish into the bucket when the printed name of the cube is "water" and the fish is not scored:
	say "It's no longer a fish out of water.";
	now the fish is scored;
	increase the score by 5.

Then you’d have to check all the other cases you mentioned – the ice melting, etc. This is verbose and you have to be careful to cover all the cases, but it works.

Or you could use an every-turn check:

Every turn when the fish is in the bucket and the cube is in the bucket and the printed name of the cube is "water" and the fish is not scored:
	say "It's no longer a fish out of water.";
	now the fish is scored;
	increase the score by 5.

This is simpler. The down side is that you’re checking every single turn. If you had fifty scored events like this, all checked every turn, it might be a bit slow.

Another option is to define a scene and put appropriate starting conditions on it. I leave that as an exercise.

thanks zarf, I’ll be sure to try these different methods tomorrow.

on another note, are you the same zarf who wrote this?

this was the most helpful thing to me when i first started playing IF, and if you are the same zarf, i’d like to know if you’d mind if i include it in my games under a help menu or something (with credit to you, of course).

If you don’t want to check the status of the puzzle every turn, you can move it to the end of the carry-out rules.

Last carry out inserting something into the bucket when the fish is in the bucket and the cube is in the bucket and the printed name of the cube is "water" and the fish is not scored:
	say "It's no longer a fish out of water.";
	now the fish is scored;
	increase the score by 5.

At the time when the cube melts:
	say "The ice cube has melted.";
	now the printed name of the cube is "water";
        if the fish is not scored and the fish is in the bucket and the cube is in the bucket:
                say "The fish is no longer a fish out of water.";
                now the fish is scored;
                increase the score by 5.
                
                

Yes, that’s me. The card is available in various formats at pr-if.org/doc/play-if-card/ . It’s a CC license so you don’t need to ask for permission to use it; just credit “Written by Andrew Plotkin — design by Lea Albaugh”.