ACTION | A modal action. | The action that this block handles. |
STRING | The action's mode. | The specific mode that this block handles, interpreted from the input. |
The onModalAction() block is called when a modal action needs to be handled. A valid onModalAction() block for the associated action and mode is resolved on the current room, then player, then the world.
If that does not exist, TAME looks for onUnhandledAction() blocks to call (on the current player, if any, and then the world).
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;
action modal a_go named "go", "move", "travel" uses modes "west", "north", "east", "south";
// Room prototypes.
room r_west;
room r_east;
room r_north;
room r_south;
room r_center
{
onAction(a_look)
{
textln("This looks like the center room.");
textln("I can go west, east, north, or south.");
}
onModalAction(a_go, "west")
{
setRoom(player, r_west);
}
onModalAction(a_go, "east")
{
setRoom(player, r_east);
}
onModalAction(a_go, "south")
{
setRoom(player, r_south);
}
onModalAction(a_go, "north")
{
setRoom(player, r_north);
}
}
extend room r_west
{
onAction(a_look)
{
textln("This looks like the west room.");
textln("I can go east.");
}
onModalAction(a_go, "east")
{
setRoom(player, r_center);
}
}
extend room r_east
{
onAction(a_look)
{
textln("This looks like the east room.");
textln("I can go west.");
}
onModalAction(a_go, "west")
{
setRoom(player, r_center);
}
}
extend room r_north
{
onAction(a_look)
{
textln("This looks like the north room.");
textln("I can go south.");
}
onModalAction(a_go, "south")
{
setRoom(player, r_center);
}
}
extend room r_south
{
onAction(a_look)
{
textln("This looks like the south room.");
textln("I can go north.");
}
onModalAction(a_go, "north")
{
setRoom(player, r_center);
}
}
player p_main
{
onUnhandledAction(a_go)
{
textln("Can't go that way.");
}
onIncompleteCommand(a_go)
{
textln("I need to GO a compass direction.");
textln("Type \"go\" and \"west\", \"east\", \"south\", or \"north\" to move around.");
}
}
world
{
onAction(a_quit)
{
quit;
}
start()
{
setRoom(p_main, r_center);
setPlayer(p_main);
textln("Type \"go\" and \"west\", \"east\", \"south\", or \"north\" to move around.");
textln("Type \"quit\".");
queue a_look;
}
afterSuccessfulCommand()
{
queue a_look;
}
}
OnAction() — Called to handle an action with another object, or a general action on the current player or room.
OnUnhandledAction() — Called if a command is valid, but an action is unhandled.
The onModalAction() 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.