Scoring Help

Hi all,

Relatively new to Inform…

I’m trying to increase the score when something is put into a container and then decrease the score when it is removed. The following snippets increase the score just fine, but neither decreases the score when the cookies are removed from their respective container.

This is what I’ve tried and I’m getting an error on code for the taking the cookie from the pocket:

After inserting the cookie into the pocket:
	increase the score by 1;
After taking the cookie from the pocket: 
	decrease the score by 1;

I’ve also tried this which doesn’t give me an error - but still doesn’t change the score when removing the cookie from the trash:

After inserting the cookie into the trashcan:
	increase the score by 1;
After taking the neutron cookie while the holder of the neutron cookie is the trashcan:
	decrease the score by 1;

Thanks in advance. Oh - there are steps that I’ve removed after the increase/decrease score steps - that’s why there are semi-colons after those steps.

It’s actually ok to end a rule with a semicolon rather than a period, provided that you have a blank line before the next rule. This can be handy when you’re moving things around in the rule; you don’t need to change the punctuation.

But anyway, the problem you’re having here is that taking the cookie from the pocket is not an action.

There’s a couple of useful tricks to find the proper name of an action, if you’re not sure. One way is to type in ACTIONS in the game and then try the command; it will print the name of the action that’s happening, and you can use that in the rule.

The other way is to look under Index → Actions → Commands and find the first word of the command, then the full pattern of the command, and read the italicised action name at the end – or clicking on the magnifying glass for more information.

In this particular case:

  • “take [things inside] from [something]” - Removing it from

So the rule that you want to write would be:

After removing the cookie from the pocket:

Don’t forget to continue the action in your After rules (or otherwise say something yourself), as otherwise the default Report rules won’t run and won’t tell the player what happened.

Thanks for the help, but it’s still not working. I’ll play with it some more.

I did find this information:

Removing is not really an action in its own right. … Because of this, it’s usually a bad idea to write rules about removing: if you write a rule such as ‘Instead of removing the key, …’ then it won’t apply if the player simply types TAKE KEY instead. The safe way to do this is to write a rule about taking, which covers all possibilities.

I’d like the score to change no matter how the cookie is taken out of the container (whether via a get, take, or remove command).

What you need is to use ‘After taking the cookie:’ since if the player types ‘Take x from y’, ‘Remove x from y’ etc. these are all ultimately, if the action successfully negotiates various rules about removing things, converted into a simple ‘Take x’. As mentioned above, you can see this conversion happening if you type ACTIONS when running the story then try out various ways of taking/removing the cookie…

The difficulty is that by the time you reach the ‘After’ stage of the action, the taking has already happened in the ‘Carry out’ stage, so the cookie is no longer in the pocket but is held by the player. Consequently conditions like ‘while the cookie is in the pocket’ will not apply in the ‘After’ stage.

Fortunately Inform retains a memory of the world state (and therefore where the cookie was) at the start of the turn, before the action began. So this works…

After taking the cookie when the cookie was in the pocket:

Another option is to use ‘the container in question’ which is set by Inform to any container that the action requires reaching inside:

After taking the cookie when the container in question is the pocket:

You could also avoid this difficulty by intervening at the Instead stage of the Take action, while the cookie is still in the pocket, and move the cookie to the player yourself, but it’s generally best to make use of the standard rules for the moving of things wherever possible, as there’s lots to think about in deciding whether or not this should be allowed. Using the After stage guarantees that all the standard checks and rules about taking something have been allowed to run and have succeeded.

A final option is to award points once all checks on the action have been carried out and passed, so it is guaranteed that the taking action will succeed and the Carry out taking rule will run, but it’s not actually happened yet:

Last check taking the cookie when the cookie is in the pocket:
     decrease the score by 1 ;

Using ‘Last check…’ guarantees that this is the very last thing to happen before Taking is actually carried out, since the Check stage happens immediately before the ‘Carry out’ stage of the action.

Slightly better than a last check would be a first carry out.

I was just thinking the same :grinning:

Thanks guys… now to figure out more stuff I don’t know :slight_smile:

You could write an every turn rule, and not worry about actions at all.

The cookie can be scored or unscored.

Every turn:
	if the cookie is unscored and the cookie is in the pocket:
		now the cookie is scored;
		increase the score by 1;
	if the cookie is scored and the cookie is not in the pocket:
		now the cookie is unscored;
		decrease the score by 1;

You can generalise that sort of thing for all objects as well. One such method:

A thing has an object called the scored receptacle.  A thing can be scored or unscored.

Definition: a thing is scorable if the scored receptacle of it is not nothing.

Every turn (this is the score scorable things rule):
	repeat with item running through scorable things:
		if the item is unscored and the item is in the scored receptacle of the item:
			increment the score;
			now the item is scored;
		otherwise if the item is scored and the item is not in the scored receptacle of the item:
			decrement the score;
			now the item is unscored.

Now all you need to do is to set the scored receptacle of some item to the place where it’s worth a point, and it happens automatically as long as it stays there.

(This only counts it if the item is directly contained by the scored receptacle. If you want to allow indirect containment as well – for example if the item is only worth a point while being carried by the player, but it still counts if it’s in the player’s pocket or backpack – then use enclosed by rather than in.)

You can of course use whatever other terms you prefer for this sort of thing.

It’s probably worth mentioning that apart from simplicity, one reason that using this type of approach to scoring (an every turn rule) may be preferable to scoring in response to specific actions is that it avoids any number of potential unanticipated ‘bugs’.

For example, if an item is scored every time the player inserts it into a pocket but unscored every time the player removes it from the pocket, if there is a character who can be persuaded to remove the item from the pocket then hand it to the player, the score can be repeatedly incremented ad infinitum.

Heh - you guys sure pointed out a lot of the stuff I don’t know… I’ll give the every turn coding a shot. Who knows, maybe I’ll actually learn it!