Page 1 of 1

Randomly Select 1 or more objects from a container object

PostPosted: Fri Jan 29, 2016 11:21 pm
by ElliotM
The following overly-complicated demo :? shows how to select one or more objects at random from a container.

Take Randomly from a Container.taf
Demonstrates a general task to allow you to take one or more randomly selected items from a container. The system is supported by a loop made from three other tasks and three variables.
(16.55 KiB) Downloaded 141 times

Example test macro/walkthrough
adrift Code: Select all
take 5 from bag
inventory
x bag

I don't expect many people to have a use for this one, and yes, this is probably easier to do in another development system, though now that I've made this once it could technically be made into a reusable module that you can import.

There is a lot of looping going on, so if you want to understand what it is doing make sure you use the debugger option in the runner so you can watch it in action. However, the bag starts with 26 objects in it, so you may want to remove a bunch before you turn the debugger on so the output is shorter because my system loops over each object in the container.

If Task FOR Loops accepted variable references, which they currently don't, I would consider trying to rework it to use those to reduce the number of tasks. At any rate, something this complicated certainly highlights the importance of choosing good variable and task names that are descriptive of what they are being used for.