OnUnhandledAction Block
OnUnhandledAction Block

OnUnhandledAction Block

OnUnhandledAction ( ACTION )

A block that describes what to do when an action is unhandled by all blocks that would normally handle an action.

Valid on Elements

Parameters

ACTION Any ACTION type, OPTIONAL. The action that this block handles.

When it is Called

The onUnhandledAction() block is called after all blocks that would ordinarily handle an action are not found. Unhandled actions are handled by the player and then the world, prioritizing a specific action over an onUnhandledAction() block that does not specify an action.

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.

Example

Unhandled Action Example


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;
	}
}

See Also

OnAction() — Called to handle an action with another object, or a general action on the current player or room.
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.

Additional Technical Notes

The onUnhandledAction() block is context sensitive involving the current player. This is assessed when finding the relevant block to execute for the current action being processed. This will affect program flow when players change.

×

Modal Header