Transitioning to a new scene when score reaches maximum

Hi all,

I’m looking for a bit of help in transitioning to a scene.

I want a room in my game to be inaccessible until the player’s score reaches 5 (the maximum score). I thought the most straightforward way of achieving this was to set up a new scene, like so:

[code]Celebration is a scene. Celebration begins when the score is 5.

When Celebration begins:
move the player to the Garden;
say “You’ve found all five tiny things![paragraph break]You can finally head into the garden”.[/code]

This kind of works, but the order the game prints the text in isn’t optimal.

When I test it by taking the toy boat (the fifth hidden object, meaning the score goes up to 5), this is what I see:

take toy boat

Garden

Description of garden.

You’ve found all five tiny things!

You can finally head into the garden.

Your score has gone up by one point, for a total of 5.


Is there a way to change the order of this, so the score line prints first, then say “You’ve found all five tiny things! You can finally head into the garden”, then have the room change to Garden, then print the description of the Garden?

"Toy Boat Legends"

Use scoring. The maximum score is 5.

When play begins:
	now the score is 4;

By the moat is a room. Player is in moat.

Garden is a room. "It's real purdy here.".

a toy boat is in moat.

Carry out taking toy boat:
	increment score;

reached-garden-yet is initially false.

Every turn:
	if reached-garden-yet is false and score is 5:
		issue score notification message;
		now the last notified score is the score;
		say line break;
		say "You’ve found all five tiny things! You can finally head into the garden.";
		now reached-garden-yet is true;
		move the player to garden;

Test me with "score/get boat/score".

The above code will do it. Explanation in next post.

-Wade

First I reproduced your problem. I then turned on the RULES testing command so I could see when various things were happening. The main issue is that the ‘notify score changes’ rule actually runs in the turn after the score has changed. Therefore, anything you do or ‘say’ in the same turn as the score increase happens before the score notification, as you discovered.

Looking at the notify score changes rule in the Standard Rules extension, I saw it uses a pretty simple method to determine whether to print the message or not:

This is the notify score changes rule:
	if the score is not the last notified score:
		issue score notification message;
		now the last notified score is the score;

So, in the case of acquiring the fifth point of the five, I’ve manually ‘issue(d) score notification message’ in the same turn you get that point, and updated the last notified score to 5 at that moment, so that the real notify score changes rule won’t do anything next turn.

The last element is using a truth state variable to make sure that this ‘You got 5 points - move you to the garden’ thing only ever happens once. I’ve used this mechanism instead of the scene-commencing one, because again, it looks like the scene text only starts printing out after the player has been moved to the garden, otherwise.

-Wade

Rather than duplicating this logic elsewhere, it’s probably better style to just:

follow the notify score changes rule;

This just tells the rule to run immediately – since the score change hasn’t been printed yet, the condition will be true and it will print it (and then not print it a second time at the end of the turn), exactly as desired. And this way you’re not depending on undocumented internals of the standard rules.

Here’s a full version of that which does use a scene:

"Toy Boat Legends"

Use scoring. The maximum score is 5.

When play begins:
	now the score is 4;

By the moat is a room. Player is in moat.

Garden is a room. "It's real purdy here.".

a toy boat is in moat.

Carry out taking toy boat for the first time:
	increment score;

Celebration is a scene. Celebration begins when the score is 5.

When Celebration begins:
	follow the notify score changes rule;
	say "You’ve found all five tiny things![paragraph break]You can finally head into the garden.";
	move the player to the Garden.

Test me with "score/get boat/score".

Note that moving the player does print a location description, so the ordering of it is important. As is ending head into the garden with a period, as that causes a paragraph break; it looks a bit weirder without one.

(You also need to be careful to put limits on rules that do things like increasing score, or you can get infinite points by repeatedly dropping and taking the boat.)

Yep, this is an improvement in the output source. Though I would say I already depended on the internals of the standard rules to get to this point. If I hadn’t looked them up and read them, I wouldn’t have been able to determine that this workaround would work. :slight_smile:

-Wade

Fair point. Although you can find the name of the rule that needed to be followed in the Index if you look in the right place (so I consider that a “documented” thing). And then you could confirm it works by experimentation, so you don’t have to look in the Standard Rules. But often it’s a lot easier to do that when you need to :wink:

Thank you both for such detailed replies! I’ll have a play around with the examples you’ve given.

One thing though which I wasn’t super clear about in my initial question: it isn’t necessarily the toy boat example which will increase the score to 5. In the game there are five hidden treasures (“tiny things”) hidden around the house for the player to find and they could be found in any order. I’m not quite sure how to account for this in the code you’ve supplied, as it could be one of five different objects that that triggers the maximum score and the move to the garden.

That’s no problem. Both of these examples trigger on the score increasing, not on what specifically caused the increase.

1 Like

I’ve just tested it and it seems to compile perfectly. Thank you both for your help!