Function: ObjectCount
Function: ObjectCount

Function: ObjectCount

ObjectCount ( OBJECTCONTAINER )

Counts how many objects an object container element owns.

Parameters

Parameter Type Description
OBJECTCONTAINER OBJECT-CONTAINER The element to count the owned objects on.

Returns

VALUE(INTEGER) The amount of objects owned.

What It Does

This function returns how many objects a specific element owns. Returns 0 if the element owns no objects, or a positive integer corresponding to the amount of owned objects.

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

GiveObject() — Gives an object to another object container.
RemoveObject() — Removes an object from its current owner.
MoveObjectsWithTag() — Moves a set of objects to another object container.
ObjectHasNoOwner() — Checks if an object has no owner.
HasObject() — Checks if an element owns an object.

×

Modal Header