(SugarCube 2/Twine 2 Browser version)
Is there a way, when using the SugarCube Pluck function to have a safeguard for a scenario where the list of array items runs out before it is supposed to?
In other words if I am plucking from an array and I have 3 items in there, but then someone clicks a fourth time.... what can I do to gracefully exit?
Can I use an || (or operator) and maybe supply it with an either: list ? Or perhaps I can have a variable check or something?
Thank you in advance.
Sage
Comments
Anyway, on the off chance that you cannot do so with whatever you're doing, then you may be able to use the logical OR operator to provide a default value, otherwise you'll have to check the returned value.
For the following examples, assume this setup:
Use the logical OR operator to provide a default value
You may use either the TwineScript or JavaScript operator: The logical OR operator isn't always usable, however, since any value which coerces to falsy will return the default, even if it's a valid value from the array (e.g. 0).
Checking the returned value
<Array>.pluck() returns undefined if the array is empty. So, unless you're stuffing your array with the undefined value, the only way to get one is to exhaust the array.
Using the <<if>> macro's def/ndef conditional operators:
Using the JavaScript typeof operator:
I haven't even tried it yet... I am about to... however... but seriously... THANK YOU
Thank you again, @TheMadExile