This is a corollary to my post about filling a 1D array with an incremented variable.
I then wanted to pick 4 unique non-repeating values out of that array, which wasn't difficult to code by using another array, but the non-repeating part has proven a bit of a challenge. Basically I have a roller with Choose, but to make sure the values don't repeat I delete the rolled value out of the original array.
The problem then is that rarely, depending on the odds, I get a 0 value out of the 4 chosen when it rolls into one of the deleted cells.
There is an easy solution, don't spawn want I want to spawn if it's the 0 value, but this screws up my odds a little.
I tried coding this a dozen different ways using the system repeat and various sub-event structures/flags with no success.
Basically nothing works, but there should be a clean solution to this.
----
I tried as a flag, for example, compare current value in the original array, if it does not equal 0, do your thing, but if it equals 0, reroll to hopefully hit another cell.
I'm not sure this works properly within the Construct logic or if there's another solution for this.
Is there something like Roll A Random Number As Many Times As Needed Until A Specified Condition Is Met?
And how would one integrate that into a typical finite system repeat block (not once per tick)?
P.S. I thought I solved this until I discovered the rare 0 values on rolls and realized what was happening.
---
P.S. Here's the capx.
http://www.darksunpictures.com/public/array2.capx
Also, is there a cleaner way of stopping the infinite loop of system repeat w/o having to increment the flag? I tried doing it with a flip between 0/1, but it didn't work.
It's doable doing it in this weird sequence, but gets a little annoying having to increment the flag on every copy of the block.
Just wondering if somebody figured out a cleaner solution.