FoxyOfJungle
Kazan Games
Hi!
My goal is to generate a final number in which it cannot be repeated, within a range of numbers from 1 to 5.
I will only use it after NOONE and before SIZE.
1 - This is what happening:
Notice that MEMORY_GAME and SWIPE_CARD were repeated in a very "close" way, when in fact it should give way to other friends that have not been added yet.
Let's say this is the repetition sequence:
[5, 2, 4, 2, 4]
2 and 4 were repeated, I want it to give way to new random numbers and not to be repeated.
What I expect:
[5, 2, 4, 1, 3]
2 - What I have:
Obviously the function is incomplete because I don't want to show the atrocities I tried using loops. (just exaggerating).
But basically, I have a
The problem is that these numbers are repeated (within the range of 1 to 5), I want them not to be repeated until I use all the numbers from 1 to 5.
When the size of the array passes the limit, I am resetting it to reinsert new non-repeatable random values.
I've tried to generate a random number and add it to an array, but I'm not able to understand how to proceed, I have a brain block, maybe because I’ve been programming for hours, I don’t know...
The numbers are repeated...
If anyone can help me with this I will be very grateful.
My goal is to generate a final number in which it cannot be repeated, within a range of numbers from 1 to 5.
GML:
enum MINIGAME_TYPE {
NOONE,
LOCKER,
MEMORY_GAME,
SEQUENCER,
SWIPE_CARD,
TEST_TUBES,
SIZE
}
1 - This is what happening:
Notice that MEMORY_GAME and SWIPE_CARD were repeated in a very "close" way, when in fact it should give way to other friends that have not been added yet.
Let's say this is the repetition sequence:
[5, 2, 4, 2, 4]
2 and 4 were repeated, I want it to give way to new random numbers and not to be repeated.
What I expect:
[5, 2, 4, 1, 3]
2 - What I have:
GML:
function showThing() {
static minigameRandomNumbers = [];
var _randomId = function() {
return irandom_range(MINIGAME_TYPE.NOONE + 1, MINIGAME_TYPE.SIZE - 1); // from 1 to 5
}
var _randomNumber = _randomId();
array_push(minigameRandomNumbers, _randomNumber); // add the random number to the end of the array
FINAL_NUMBER = _randomNumber; // ???
// reset array if larger
show_debug_message(minigameRandomNumbers); // show array contents
if (array_length(minigameRandomNumbers) >= MINIGAME_TYPE.SIZE - 1) {
minigameRandomNumbers = [];
}
}
But basically, I have a
static
array, that means it is declared only once, so I can add the new random values each time I use the function.The problem is that these numbers are repeated (within the range of 1 to 5), I want them not to be repeated until I use all the numbers from 1 to 5.
When the size of the array passes the limit, I am resetting it to reinsert new non-repeatable random values.
I've tried to generate a random number and add it to an array, but I'm not able to understand how to proceed, I have a brain block, maybe because I’ve been programming for hours, I don’t know...
The numbers are repeated...
If anyone can help me with this I will be very grateful.
Last edited: