TADS Shuffled List

TADS newbie here.

I need to shuffle a list of objects “lst” .

I’ve tried this (this is all local within a method in a room object):

local shuffled = new ShuffledList(lst);

but when I iterate through this list:

local y;
        foreach (y in shuffled)
        {
            "This object name is <<y.globalParamName>>\n";
        }

nothing prints and the shuffled list seems to be empty.

I’ve also tried something like:

shuffled.valueList = lst;

but no go.

I know that my original unshuffled list is valid because I CAN iterate through that and get back the object names.

1 Like

Try iterating through shuffled.valueList after you’ve created it.
I don’t know your situation of course, but I wouldn’t think you would want to store a ShuffledList in a local, unless you are just setting something up. You’re more likely to store something like that in a property of an object.

2 Likes

well, that’s progress. I get the objects back when I iterate using shuffled.valueList. except it’s not shuffled. even after a reshuffle() it’s the same as the base unshuffled list.

I’ve also tried moving the shuffled list out of the local object using:

+ shuffled: ShuffledList
;

I get the same thing, the objects are there but they’re not shuffled.

1 Like

I think you’re meant to access successive items from a ShuffledList by using its getNextValue() method rather than by iterating through it with foreach.

1 Like

yup, that’s it. i was confusing the class list with the datatype list and iterating it incorrectly.

thx!

1 Like

I suspect that as you keep going you will start to pick up on the TADS mentality and things like this will start to come more naturally! Note also that ShuffledEventList is far more commonly used than ShuffledList although ShuffledList certainly has its place…

1 Like

I was to suggest that you should also look at shuffledEventList and shuffledList, so I concur and agree with johnnywz00…

Best regards from Italy,
dott. Piergiorgio.

1 Like