ACTION | GENERAL, OPEN, or TRANSITIVE action (depending on the element type). | The action that this block handles. |
The onAction() block is called when a general or open action needs to be handled at the world, player, or room element.
If a valid onAction() block for a general or open action on the current room is not found (or no current room), TAME then looks for a valid onAction() block on the current player. If that is not found, (or no current player), TAME then looks for a valid onAction() block on the world. If that is not found, TAME looks for onUnhandledAction() blocks to call (on the current player, if any, and then the world).
Then if that is not found, an ERROR cue is added to the Response.
The onAction() block is called when a transitive action needs to be handled on an object element.
If an onAction() block is not found on the target object, TAME looks for onActionWith(), onActionWithAncestor(), then onActionWithOther() blocks on the current room, if any, the current player, if any, and then the world. And if that does not exist, TAME looks for onUnhandledAction() blocks to call (on the current player, if any, and then the world).
Then if that is not found, an ERROR cue is added to the Response.
Non-strict ditransitive actions that lack a second object are treated as transitive actions.
Inheritance rules apply when searching for callable blocks, always!
If this block is executed, it counts as a "successful command", so this will execute the afterSuccessfulCommand() block after the initial action handling and queued actions.
action general a_quit named "quit";
action general a_look named "look around", "look";
action general a_dance named "dance";
action general a_identifyself;
action general a_switch named "switch", "switch player";
action transitive a_examine named "look at", "examine";
action transitive a_use named "use";
object o_ball named "ball" uses determiners "the"
{
onAction(a_use)
{
textln("You dribble the ball. Fun!");
}
onAction(a_examine)
{
textln("It looks like a ball.");
}
onRoomBrowse()
{
textln("There's a ball, here.");
}
}
object o_thing named "thing" uses determiners "the"
{
onRoomBrowse()
{
textln("There's a thing, here.");
}
}
room r_main
{
onAction(a_look)
{
textln("You look around the room.");
browse(this);
}
}
player p_second; // declare for later use.
player p_first
{
onAction(a_identifyself)
{
textln("I am the first player.");
}
onAction(a_dance)
{
textln("You do a jig.");
}
onAction(a_switch)
{
textln("Switching to second player.");
setPlayer(p_second);
}
onUnhandledAction(a_use)
{
textln("I can't use that.");
}
onUnhandledAction(a_examine)
{
textln("I can't examine that.");
}
onUnhandledAction()
{
textln("I can't do that.");
}
}
extend player p_second // finish declaring
{
onAction(a_identifyself)
{
textln("I am the second player.");
}
onAction(a_switch)
{
textln("Switching to first player.");
setPlayer(p_first);
}
onUnhandledAction(a_use)
{
textln("Nope. Can't use that.");
}
onUnhandledAction(a_examine)
{
textln("Nope. Can't examine that.");
}
onUnhandledAction()
{
textln("Nope. Can't do that.");
}
}
world
{
onAction(a_quit)
{
quit;
}
onUnhandledAction(a_dance)
{
textln("I can't dance.");
}
start()
{
setRoom(p_first, r_main);
setRoom(p_second, r_main);
setPlayer(p_first);
giveObject(room, o_ball);
giveObject(room, o_thing);
browse(room);
queue a_identifyself;
}
}
OnActionWith() — Called by ditransitive or transitive actions for handling an action with another object.
OnActionWithAncestor() — Called by ditransitive or transitive actions for handling an action with another non-specific object.
OnActionWithOther() — Called by ditransitive or transitive actions for handling an action with another object after no specific entry points exist.
OnUnhandledAction() — Called if a command is valid, but an action is unhandled.
The onAction() block is context sensitive involving the current player or the current room. This is assessed when finding the relevant block to execute for the current action being processed. This will affect program flow if rooms and players change.