ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Randomly Select 1 or more objects from a container object

This forum is the place to learn about and discuss ADRIFT 5. Feel free to mention any bugs you find here, but please also add these to the Bugs & Enhancements list.

Please also refer to the ADRIFT 5 Wiki for more information.

Randomly Select 1 or more objects from a container object

Postby ElliotM » Fri Jan 29, 2016 11:21 pm

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 32 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.
ElliotM
 
Posts: 1183
Joined: Tue Apr 17, 2007 8:04 pm
Location: The Midwest in the USA

Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 3 guests