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?

  • VioneT@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    4 months ago

    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:

    output
      Fruit</b>: [fruit = fruit.consumableList,("")][x = fruit.selectMany(1,3).map(a => a.evaluateItem), x.includes('None') ? 'None' : x.joinItems(", ")]
    

    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, the condition ? 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: