I’ve come across a potential bug or unexpected behavior of .consumableList.

For example, we have the following lists:

animal
  pig
  cow
  chicken
  zebra
  crayfish
  jellyfish
  worm

output
  [x = animal.selectMany(5).consumableList, x.joinItems(", ")]

For example, x is a consumable list with 5 items like so: cow, cow, pig, chicken, zebra. The output will then output cow, cow, pig, chicken, zebra.

Then, to select the items from the consumable list, we can use x.selectOne. Outputting it:

output2
  [x.selectOne] [x.selectOne] [x.selectOne] [x.selectOne] [x.selectOne]

The expected output should be any combinations of ‘cow, cow, pig, chicken, and zebra’ e.g. cow pig cow zebra chicken.

However, it throws an error Looks like your consumableList ran out of items. This is the list in question: cow, cow, pig, chicken, zebra, and outputs an undefined.

I believe it is because consumable list takes ‘unique’ items. In which, the items in the list have only ‘4’ unique items (cow, chicken, pig, zebra), but it has 5 items (cow, cow, chicken, pig, zebra).

I think the correct behavior of a ‘consumable list’ is to be able to deduct an item from a list and prevent it from being selected again (consuming it), instead of creating a ‘unique list’.

Here is an example generator with the said problem.

  • @perchanceM
    link
    English
    2
    edit-2
    1 year ago

    Thank you! Should be fixed now.

    Technical details, if you’re curious: The consumption code was relying on the “identity” of an item to know whether it has been consumed, which works for lists because each item has its own unique identity, but not with the JS array that is produced by selectMany because arrays can contain several instances of the exact same item. By “same item” and “identity”, I mean not just that the text is the same, but the actual underlying data that they’re pointing to in the computer’s memory is the same. Like variables all pointing to the same list - e.g. [animalListAlias=animalList] will mean that animalListAlias refers to the exact same thing as animalList (rather than being a “copy” of animalList). So I’ve switched it so the “consumption tracking” uses “indices” of the array rather than the array items themselves. I think this should work fine, but let me know if you notice anything strange.

    Thanks again for reporting this!

    • VioneTOPM
      link
      English
      21 year ago

      Thanks for updating it 🤗