Question involving After rules...

I solved the problem another way, but I am still mystified about why the following will not work the way I want it to–

After taking the velvet bag: if the velvet bag is not handled: say "You feel suffused with power for a moment. But then, as if the bag sensed that you are not its owner, the feeling recedes. However..."; now delivery is 1;['delivery' is a numeric variable I set up--if it is 1, this sets another set of circumstances going once the player leaves the room] now gooddeed is "for finding Natalie's mojo...that's it....no more need be said";['gooddeed is part of a quote I set to tell the player why his score just increased] increase score by 10; otherwise: say "You feel a surge of power for a moment, but shortly it subsides."

What this was supposed to do was award points to the player when he picks up the bag the first time. The problem I was having was the program acted as if the bag had already been handled, so when I tested it, it would always render the ‘otherwise’ result, even at the first taking. And what was to happen later(as a result of ‘delivery’ being 1) did not occur, and the score did not increase. I solved the problem, using other methods, but I am just puzzled about why this one did not work. My game uses many After rules which all tested well.(by the way, the code above may not look right because I entered it here manually and it did not let me use tabs)
Thanks!

You know, now that I have proofread my question, I am beginning to think that perhaps it didn’t work because a successful ‘taking’ results in the object being ‘handled’, and this was why the first condition was skipped, even after the first ‘taking’? Am I right?

Yes. Try “if the velvet bag was not handled:”.

Thanks Vince,
Yep now I seem to remember reading about ‘was’ in the manual. Thanks(embarrassedly)

(I intended to comment on this in your other thread about text variables, but now’s a good opportunity.)

As a matter of style, I prefer to use multiple rules with conditions ("when ") rather than to have a single rule with lots of conditionals in its body. I think that it improves readability by reducing the indentation level and by grouping the things that will happen in a particular scenario together in a rule by themselves. It does cause the reader to have to consider more rules at once, but the rules are usually placed together in the source code, and the reader would have had to consider the conditional logic anyway.

I’d write your after rule as:

After taking the velvet bag when the velvet bag was not handled:
	say "You feel suffused with power for a moment.  But then, as if the bag sensed that you are not its owner, the feeling recedes.  However...";
	now delivery is 1;
	now gooddeed is "for finding Natalie's mojo...that's it...no more need be said";
	increase score by 10.
		
After taking the velvet bag, say "You feel a surge of power for a moment, but shortly it subsides."

This technique hinges on two things: (1) An after/instead rule, in the absence of an explicit “continue the action”, will end action processing, and (2) a rule with a more specific condition will run before a rule with a more general condition.

Vlaviano’s code works because the first After rule is supposed to run once. It’s good to understand though that After rules will stop when they run and won’t continue to the Report phase-they’re intended usually to override that. If you have two after rules and need them both to run, or you want the regular Report rules to run, the Afters must have “continue the action;” after them.

Normally I think you’d want to make the first After a Carry out rule because you usually want the silent stuff to happen in that phase.

[code]Carry out taking the velvet bag for the first time:
now delivery is 1;
now gooddeed is “for finding Natalie’s mojo…that’s it…no more need be said”;
increase score by 10.

After taking the velvet bag for the first time:
say “You feel suffused with power for a moment. But then, as if the bag sensed that you are not its owner, the feeling recedes. However…”;

Last report taking the velvet bag, say “You feel a surge of power for a moment, but shortly it subsides.”[/code]

Making the second a Last Report rule lets the parser say the default take response as well.

Report rules do not stop by default. Since your message does not clarify the player actually took the bag, that’s one way to solve it.

If I remember the author’s other code correctly, “increase score by 10” isn’t a silent phrase–it prints the gooddeed message and a notification that the score has gone up. So that’s a reason to fold it into the After rule, to make sure that the gooddeed message and score notification print after the message about taking the bag.

Score notifications – the “[Your score has just gone up by…]” message – are collected and displayed at the end of the turn. They never appear before action reports.

This is true in the sense that check rules validate the preconditions for an action, carry out rules carry out the action by updating the world model, and report rules communicate the results of the action to the player. Considering these three kinds of rules alone, the silent stuff usually does go in a carry out rule, while the non-silent stuff goes in a report rule.

However, I tend to reserve check, carry out, and report rules for general behaviors of an action or behaviors of an action on broad classes of objects. The idea being that these rules could be cut and pasted out of the current game and into another game that contains the same action without being changed. I use before, instead, and after rules for behaviors that apply to game-specific objects like the velvet bag. This isn’t absolutely necessary, and it’s not always possible since some actions can’t be separated from the game in which they appear, but the discussion in §12.21. (Guidelines on how to write rules about actions) about particular situations vs. general rules of play does point authors in this direction.

OK, I was misremembering the “gooddeed” code, which gets hooked into the announce the score rule response (D). Which I guess would make sure that the message about your score going up would appear after the word “However…” as it ought to. Though if you have any Every Turn rules running, there may be a risk that they will print a message that goes between the “However…” message and the score notification message.

Thank you all for your input. Here’s how I coded it–

After taking the velvet bag for the first time: say "As your hands grasp the bag, you feel a momentary surge of power, but then, as if the bag senses that you are not its owner, the feeling recedes. However..."; now gooddeed is "finding Natalie's mojo...that's it...there's no more to say here..."; now delivery is 1; increase the score by 10. Report taking the velvet bag: if the velvet bag is handled: say "You feel the power of the bag, fleetingly, as you take it..."
The After rule for the initial taking; the Report rule for subsequent ‘takings’–which prints a succinct ‘Taken.’ after the ‘say’ phrase. As the object in question, the bag, will be playing a climactic role, I decided that this was the effect I want.

One caution with “for the first time” rules is that they aren’t guaranteed to run.

By which I mean: if there’s a rule which prevents you from taking anything while wearing the oven mitts, and the player tries to pick up the bag for the first time while wearing oven mitts, then its “for the first time” will be used up. “For the first time” means the first attempt, not the first success.

However, if there’s no way for the player to try and fail to take the bag, “for the first time” is exactly what you want.