Re: TADS contents dumping


26 Nov 1995 12:51:27 GMT

ErsatzPogo (ersatzpogo@aol.com) wrote:
: Is there an elegant way in TADS to have an object's entire contents moved
: to a new location (for example, dumping them all on the ground)? I'm
: currently using this grungy old "for" loop, and it coughs and wheezes and
: refuses to start on cold mornings, and I'm definitely looking to trade up.

I don't know if this counts as elegant, but I use code similar to this
at one point. And yeah, it's a "for" loop...

emptyObject: function( obj, dest )
{
local tot, i;
local list := obj.contents;

if ( itemcnt ( list ) )
{
tot := ( length( list ) );
for( i := 1; i <= tot; i++ )
list[ i ].moveInto( dest );
}
}

Note that I'm lazy and haven't tested this exact piece of code - I took
an existing function of mine, pulled out a bunch of lines that are specific
to my own class libraries, and left the rest. So this isn't the most
efficient way to code it, and hey - it may not work. I think it will
though...

What it's supposed to do is take the listable contents of a given object
(obj) and transfer them to the destination - dest. Note that I'm using
the itemcnt() adv.t function, as this function isn't meant to move
non-takeable objects.

- Neil K.

--
    Neil K. Guy  *  neilg@sfu.ca  *  tela@tela.bc.ca
        49N 16' 123W 7'  *  Vancouver, BC, Canada