How do you move a Thing into Player Inventory?

I am in my second day of learning TADS 3, so this may be a very newbie question.

I have a hidden crowbar that is revealed when the player looks behind a crate. This actually works as expected, but I thought instead of having the player to take the crowbar after discovering it, I could make it easier by directly moving the crowbar to the player’s inventory.

ego: Actor
	location = seaplaneInterior

seaplaneInterior: Room 'Seaplane Interior'
	"You see two seats for the pilot and co-pilot and the flight controls. There
	is a storage crate secured in the rear compartment. A beach area is outside
	the craft. "

+ OpenableContainer, Heavy 'storage crate/box' 'crate'
	"A wooden crate secured in place so it does not move around while flying. "

	/* Reveal the crowbar on looking behind the crate */
			if (crowbar.location)
				say('You see nothing else behind the crate. ');
				crowbar.location = ego;
				say('You find a crowbar behind the crate. You take it. ');

crowbar: Thing 'crowbar' 'crowbar'
	"A metal crowbar that can pry containers open."

Yields this output:

>look behind the crate
You find a crowbar behind the crate. You take it. 

You are empty-handed. 

Obviously crowbar.location = ego does not work, I also tried ego.contents.append(crowbar) with no success.

Any help would be much appreciated.

1 Like

You should use moveInto function in this case.

Try this code: crowbar.moveInto(ego);


Wonderful, thank you @He4eT. I see the moveInto function in the Library Reference, knowing what to search for is the trick.


You might also consider making things like the crowbar a Hidden, and make the crate a RearContainer (actually a ComplexContainer with a RearContainer as part of it, but you can look that up in Learning TADS 3 or some of the other docs)… that way hidden things are revealed automatically when you look behind (or under, or in, depending on which object you use) the object.

@Wesley With TADS, it’s very important that you use the right method to move things around. Calling moveInto performs some operations behind the scenes that just changing the crowbar’s location property does not, which is probably why it failed.

In general, do not change any properties of an object directly, but dig through the Adv3 library to find out which method does what you want. Direct changes to properties are not detected by TADS and may defeat the purpose of Adv3.

A common pitfall, for example, is moving actors around by changing their location property. In the case of actors you’re not even supposed to use moveInto but rather moveIntoForTravel among other options (there’s a whole article about all the ways you can shoot yourself in the foot with actor travel).

1 Like

Thanks for the suggestions @johnnywz00 and @henck, and for the article link on NPC Travel. Much appreciated.