Function: RemoveObjectWithTag
Function: RemoveObjectWithTag

Function: RemoveObjectWithTag

MoveObjectsWithTag ( SOURCE, DESTINATION, TAG )

Moves a set of objects owned by one object container that matches a tag to another container.

Parameters

Parameter Type Description
SOURCE OBJECT-CONTAINER The element to take objects from.
DESTINATION OBJECT-CONTAINER The element to give objects to.
TAG VALUE(STRING) The tag to match.

Returns

Returns nothing. Cannot be used in expressions.

What It Does

This function takes a set of objects with a specific tag belonging to the source object container and moves them to the destination object container.

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.
ObjectHasNoOwner() — Checks if an object has no owner.
ObjectCount() — Returns the amount of objects an element owns.
HasObject() — Checks if an element owns an object.

Additional Technical Notes

The order in which the objects are moved depend on the order in which they were added to the source object container.

×

Modal Header