Oh right. So, I'll show you the data I'm dealing with:
I set up this in some passage:
<<set $pcPierced.ears.scale = 1>>
<<set $pcPierced.ears.desc = "''your ears pierced,'' the little silver sleepers catching the light">>
<<set $pcPierced.navel.scale = 1>>
<<set $pcPierced.navel.desc = "''your navel pierced,'' the jewelry there hanging down from it, glittery and gorgeous">>
<<set $pcPierced.tongue.scale = 1>>
<<set $pcPierced.tongue.desc = "''your tongue pierced,'' the silvery stud often making an appearance whenever you might open your mouth">>
<<set $pcPierced.face.scale = 2>>
<<set $pcPierced.face.desc = "''your lip pierced,'' a silver ring on one side to catch attention, //and your eyebrow too,// another silvery ring">>
<<if setup.pcIsPierced()>><<listingRand "$pcPiercings" 3>><</if>>
All that is just for testing, not as I'll be using it (quite) in the game. But, for testing formats, it's good.
I have this defined in StoryInit:
<<set $pcPierced = {
ears: { scale: 0, desc: "" },
navel: { scale: 0, desc: "" },
tongue: { scale: 0, desc: "" },
face: { scale: 0, desc: "" }
}>>
And I have this defined too:
<<set $pcPiercings = []>>
So, I know the names are pretty similar, they are quite different. For testing, I'm just first loading the $pcPiercings array with data. That's the one that eventually gets overwritten. And that's desired, since it's there for just that.
I have another version of the widget I was using before moving to a more generalized approach. It's this:
<<widget "piercingsRand">>
<<set _piercingList = setup.pcGetPiercingDescs()>>
<<if $args[0] > _piercingList.length>>
<<set $args[0] = _piercingList.length>>
<</if>>
<<set $pcPiercings = _piercingList.randomMany($args[0])>>
<</widget>>
So, I think that's about all you really need to see. Oh, and the javascript function:
/* Returns a new array of all piercing part descs, where scale > 0. */
setup.pcGetPiercingDescs = function () {
var sv = State.variables;
return Object.keys(sv.pcPierced).reduce(function (a, c) {
return sv.pcPierced[c].scale > 0 ? a.concat(sv.pcPierced[c].desc) : a;
}, []);
};
I only really use the object for seeing which descs I pull to push into the array. From there, I'm just using array functions to shuffle and then downsize.
So, in the end, you get something like this:
[ "''your tongue pierced,'' the silvery stud often making an appearance whenever you might open your mouth", "''your ears pierced,'' the little silver sleepers catching the light" ]
What think? The only real question I have is... how to pass the variable in, and make use of it directly, as opposed to using temporary variables and then handing over the result at the end. That's pretty much how I'm doing the other version. And that one works. I wonder... if we can't get the generalized one to work too?
But, it's it not really something that's been designed, I could just go back to the old version. I just thought... I could just this for four arrays I have. To shuffle, and then print in a pretty nice list. They're all the same. Just arrays of string fragments.