Hi,
I am trying to make a unique random number picker for a project.
The issue I seem to be having is that the loops I created to carry out this process only seem to be iterating one time and not "looping." I am wondering if I am not setting the loops up properly (meaning physically, nesting the condition and sub-events properly in the event sheet).
My intentions are to repeatedly pick a random number, compare it to the members of a picked-number-log array. If it matches a member of the array, the program will pick another number and try again. If it does not match anything in the array, the program will add that number to the array and return that value as "thisIssue."
(I am using the result of this as an Index to pick some JSON data.)
Currently, I created a function ("issuePicker") that contains a Loop (I've tried both WHILE and REPEAT with the same result) that should repeat until a "unique" condition is satisfied (unique < 1).
When the WHILE/REPEAT loop starts, it picks a random number (assigns it to the var "thisIssue").
I then run a ForEach loop on a "issueLog" array and compare each member to "thisIssue".
If a match is found, it adds 1 to the variable "unique" (unique = unique+1).
If no matches are found, "unique" remains at 0.
In the next condition, I check If unique < 1 and if so, Stop Loop.
What I believe should be happening is that for each iteration of the WHILE/REPEAT loop, the ForEach Loop inside of it should execute for each number of elements in the "issueLog" array. If any of the ForEach checks fail, the WHILE/REPETE loop should iterate again and so on until an actual unique random number is found.
What seems to be happening, however, is that the For Each loop is only executing one time and the WHILE/REPEAT loop is also executing one time. Even if I screwed up the exit process for the WHILE/REPEAT loop, (I think) I should be seeing the For Each loop iterate for at least the number of times there are elements in the "issueLog" array. Correct?
(I added a test text box and have some "append texts" that should be appending the LoopIndex for the ForEach and the counting and displaying the loops for each WHILE/REPEAT iteration. Both of these text boxes only show a single entry for each of these every time I run the "issuePicker" function.
When I look at debug, I can see that the random numbers ("thisIssue") is getting added to the "issueLog" array. (In addition I put some dummy entries in the "issueLog" array to start with just for testing... so the For Each should be running multiple times, but it is not. I even tested my WHILE loop by adding the condition "unique < 10000" (just to see if it would hang up my program for 10000 loops) there was no difference.
Does anyone have any ideas? Does it have something do with my putting the loop inside of a function? Am I just not nesting the conditions and sub-events properly?
Any help would be greatly appreciated.
Thank you,
J