Okay so I’m working on a generator that has a lot of different sections and in each section, they have a chance to roll a “None”
However, most of the sections can roll multiple outputs. I was wondering if there is a way to have it so that if “None” is rolled then there will be only one output. I assumed this would be done with if/else statements but I’m not sure how I’d format it.
If this is possible, would it have to be done for every section or would there be a way to have it as an ‘overall rule’ for the generator?
On your output, you could check if the selected items includes the ‘None’, if it has, then you output ‘None’, otherwise, you output all the selections:
Since
.selectMany()
returns an Array of Objects,.map(a => a.evaluateItem)
just makes sure that the array has ‘strings’ and not ‘objects’ (Perchance List)..includes()
is a JavaScript Array Method to check if the Array includes the passed item. Also, thecondition ? if true : if false
syntax is a ternary operation, but you can use normal if else there like:[x = fruit.selectMany(1,3).map(a=>a.evaluateItem); if (x.includes('None')) { 'None' } else { x.joinItems(",") }]
.References:
.includes()
- MDN - JavaScript - Includes.map()
- MDN - JavaScript - MapThis helped so much, thank you!