Scripting Exercise:  AssumeRoleIf
The AssumeRoleIf script gets used a lot.  For every Event, the Engine uses AssumeRoleIf to test all the Actors for the Roles to be filled in the Verb

Click once on the AssumeRoleIf button, right underneath the "Role" box. Once again you get an empty Script, but this time instead of a default number, you see this:

The word "Condition?" is
what we call a prompt: its purpose is to prompt you to replace it with something, in this case, the condition that will determine whether an Actor assumes the Role.
Note that this prompt is black. That's because the AssumeRoleIf Script is a yes-or-no Script (boolean), which we express as "true-or-false."

Click on the Condition? prompt, and note that once again, some menus light up. Click on some of the menus you clicked on previously. Surprise! They show different menu items this time. Thatís part of our "can't mix apples and oranges" protection system for you. After all, it would be nonsense for you to enter 0.5 for the Condition?, because 0.5 is not a boolean (true-or-false) value. It's just wrong here, so SWAT won't let you use it or anything else that wouldn't fit.

Let's go back to the original idea for the Role "punchee." The punchee is the DirObject of the Verb of this Event. But we don't tell the Engine "The punchee is the DirObject of the Verb of this Event." Instead, we do it backwards. The Engine goes through each of the Actors one at a time and asks the AssumeRoleIf Script, "Does this Actor fit your requirements?" We need to write an AssumeRoleIf Script that answers that question. The condition that we want is that the Actor (whom we call the ReactingActor) is the DirObject of this Event. (i.e., the one who was punched).

Make sure "Condition?" is still highlighted.  (If you accidentally changed it, click on that top item and hit "delete" to go back to the "Condition?" prompt.)  Click the large button below "delete" that says "AreSameActor."  The condition changes to AreSameActor, and the "Actor1?" prompt is now highlighted.

Select "ReactingActor" (the Actor who has assumed this Role).  The Engine will use the comparison Operator "AreSameActor" to test whether the current Actor meets the requirements for the Role.  We're checking to find which "ReactingActor" is the DirObject of the Verb "punch," so For "Actor2?" choose "ThisDirObject."

Our script is done:

This means "Assume the
Role if the ReactingActor and ThisDirObject are the same Actor."

Yes, it's a backwards way of saying it, but it still makes sense. If you're wondering,
ThisDirObject means "the DirObject of this Event, the one we're reacting to."

This backwards way of thinking is one of the most difficult concepts in SWAT. Instead of asking "Who should assume the
Role?" we ask "What conditions specify whether an Actor should assume the Role?" There's a reason for this backwardness: the conditions might demand none, one, or many Actors to fill the Role. If we phrase the question in the normal way, then the answer must be phrased like this:

Who should fill the
RoleJoe should fill the Role.

That implies exactly one
Actor to fill the Role. But if we phrase the question in the backwards way, we can give a more complex answer:

What conditions specify whether an
Actor should fill this Role? These conditions.

Then we just try those conditions out on every
Actor and see who ends up fitting those conditions, which could be none, one, or many Actors.

Don't feel bad if this concept leaves you baffled at first; it really is counterintuitive. It will take a while before you feel comfortable with it. But with practice, it sinks in and pretty soon backwards thinking you comfortable with will be. In the next lesson, we'll be using this kind of backwards thinking more broadly.

Previous tutorial:  Scripting Basics                                                                  Next tutorial:  Acceptable and Desirable