TADS3 How can I specify quantity of items moved into player inventory?

Howdy.
Newbie question, but how do I add multiples of an item to player inventory. I’ve been using this:

exampleObject.moveInto(me);

And while it works, I can’t move more than one “exampleObject” into “me”. Is there a way to specify a quantity for “exampleObject”? Am I just going about this the wrong way?

I’ve been thumbing through TADS3 documentation for a hot minute and I can’t find or have overlooked the solution. Sorry it’s staring me straight in the face.
Thanks.

1 Like

Look at CollectiveGroup. There is a thread here that will most likely help you.

1 Like

You can only have one object named exampleObject in your game, so multiple instances of it can’t exist to move. You could move a list of objects with code like this:

foreach(local obj in objList)
   obj.moveInto(me);

Or if you want to move count objects of the SampleObject class you could do something like:

moveMulti(count)
{
     local i = 0;
     for(local obj = firstObj(SampleObject); obj != nil; obj = nextObj(obj, SampleObject) )
     {
       if(obj.location != me)
       {
            obj.moveInto(me);
            if(++i >= count)
                break;}
       }
     }
} 

This will keep moving objects of the SampleObject class into me either until count objects have been moved or the game runs out of SampleObjects to move.

4 Likes

I would echo the primary issue would be if exampleObject is defined as a single object, and not a Multi-Inst or something. Eric’s SampleObject would be a way to define a class whose instances could respond the way you want (you would need to define what verbs invoke the moveMulti function, probably a custom version of Take).

CollectiveGroups allow you to collect individual instances into a group for reporting, examining and optionally manipulating. See section 15.3 of the adv3 documentation (not sure what section adv3lite?)

As an FYI, there is a subtle bug in CollectiveGroup in adv3 for objects that can be spread around the game. Should you go down that path, documented here.

3 Likes