Function: Browse
Function: Browse

Function: Browse

Browse ( OBJECTCONTAINER )

Browses an object container element, executing the "onBrowse" blocks for each object owned by the element.

Parameters

Parameter Type Description
OBJECTCONTAINER OBJECT-CONTAINER The element to browse.

Returns

Returns nothing. Cannot be used in expressions.

What It Does

This function takes the provided element and iterates through the objects it owns, calling the appropriate "on[Type]Browse" blocks on each object.

The block called depends on the object-container type browsed - first, each object's OnElementBrowse() block is resolved for the browsed element, then for the element's ancestors, and if none of those are found nor called, it will call either the object's OnContainerBrowse(), OnRoomBrowse(), OnPlayerBrowse(), or OnWorldBrowse() block, depending on what element type owns the object.

If none of the "browse" blocks are on an object, that object is skipped for browse.

Example

Object Ownership Example


action general a_quit named "quit";
action general a_takeall named "take all", "take everything";
action general a_dropall named "drop all", "drop everything";
action transitive a_take named "take", "pick up", "t";
action transitive a_drop named "drop", "discard", "d";
action transitive a_examine named "examine", "look at", "x";

object archetype o_all
{
	onAction(a_take)
	{
		if (hasObject(player, this))
			textln("You already have this.");
		else
		{
			giveObject(player, this);
			textln("Taken.");
		}
	}

	onAction(a_drop)
	{
		if (!hasObject(player, this))
			textln("You don't have this.");
		else
		{
			giveObject(room, this);
			textln("Dropped.");
		}
	}

}

object o_scissors : o_all named "scissors", "pair of scissors" uses determiners "the" tagged "takeable", "useful"
{
	onAction(a_examine)
	{
		textln("Looks like a pair of scissors.");
	}

	onPlayerBrowse()
	{
		textln("A pair of scissors.");
	}

	onRoomBrowse()
	{
		textln("A pair of scissors is here.");
	}

}

object o_ball : o_all named "ball" uses determiners "the" tagged "takeable"
{
	onAction(a_examine)
	{
		textln("Looks like a ball.");
	}

	onPlayerBrowse()
	{
		textln("A ball.");
	}

	onRoomBrowse()
	{
		textln("A ball is lying on the ground.");
	}

}

object o_key : o_all named "key", "small key" uses determiners "the" tagged "takeable", "useful"
{
	onAction(a_examine)
	{
		textln("Looks like a small key.");
	}

	onPlayerBrowse()
	{
		textln("A small key.");
	}

	onRoomBrowse()
	{
		textln("A small key is here looking unused.");
	}

}

room r_main;

player p_main;

world
{
	init()
	{
		setPlayer(p_main);
		setRoom(p_main, r_main);

		giveObject(r_main, o_scissors);
		giveObject(r_main, o_ball);
		giveObject(r_main, o_key);
	}

	function seeAll()
	{
		textln("");
		if (objectCount(room) > 0)
		{
			textln("In this room:");
			browse(room);
		}
		else
		{
			textln("There's nothing in the room.");
		}
		textln("");
		if (objectCount(player) > 0)
		{
			textln("I have:");
			browse(player);
			textln("");
			textln("But these look useful:");
			browseTagged(player, "useful");
		}
		else
		{
			textln("I have nothing.");
		}
	}

	start()
	{
		textln("Type \"take\" to take objects, and \"drop\" to put them down.");
		textln("Type \"examine\" to examine objects.");
		textln("Type \"take all\" to take all objects.");
		textln("Type \"drop all\" to drop all objects.");
		textln("");
		textln("Type \"quit\" to quit.");
		seeAll();
	}

	onAction(a_quit)
	{
		quit;
	}

	onAction(a_takeall)
	{
		moveObjectsWithTag(room, player, "takeable");
		textln("Took everything.");
	}

	onAction(a_dropall)
	{
		moveObjectsWithTag(player, room, "takeable");
		textln("Dropped everything.");
	}

	afterEveryCommand()
	{
		seeAll();
	}

}

See Also

BrowseTagged() — Browses an object-container element's owned objects that have a matching tag.

Additional Technical Notes

Objects are browsed in the order in which they were added to their current owner.

×

Modal Header