0 votes
by (8.9k points)

Hi, Twine Masters!

I'd like to populate my Sets with multiple items.  Currently, here's how I'm doing it:

<<set
   $npc.memberOf to new Set(),
   $npc.memberOf.add("marsh family"),
   $npc.memberOf.add("esoteric order of dagon")
>>

This works fine, but I wonder if there's a way to code it more efficiently.  I tried this:

<<set $npc.memberOf to new Set("marsh family", "esoteric order of dagon")>>

And this:

<<set 
   $npc.memberOf to new Set(),
   $npc.memberOf.add("marsh family", "esoteric order of dagon")
>>

But neither method worked.  Is there a better way?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

Both @TheMadExile and myself supplied a link to the Javascript Set object's documentation in our answers to your previous Set related questions. If you had looked at that documentation you would of seen how to initial a Set object with multiple values within both the Syntax section and within the "Iterating Sets", "Implementing basic set operations", and "Relation with Array objects" examples.

eg. TwineScript example.of initialising a Set object using an Array of numerical values.

<<set _var to new Set([1,2,3,4,5])>>

var: _var
has 2: <<= _var.has(2)>>
has 6: <<= _var.has(6)>>

 

by (8.9k points)
Thanks, Greyelf.  It looks like I'm going to have to bite the bullet and learn some JavaScript!  :-O
...