Function: GiveObject
Function: GiveObject

Function: GiveObject

GiveObject ( OBJECTCONTAINER, OBJECT )

Adds an object to an object container element.

Parameters

Parameter Type Description
OBJECTCONTAINER OBJECT-CONTAINER The element to add the object to.
OBJECT OBJECT The object to add to the element.

Returns

Returns nothing. Cannot be used in expressions.

What It Does

This function adds a specific object to an object container element, such that its ownership changes to the new object container. Since an object cannot have more than one owner, this will remove the object from its current owner, if it has one.

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

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

×

Modal Header