1st event and its sub event is auto generating array for me
So if you create your manually you can skip it
So 2nd (last) event is what allows me to pick random number without repeating choice until all choices are chosen at least once
BUT issue is
Imagine i have only 4 child vars so only 4 choices
Now imagine just for example they go in order 2 1 4 3
And now 3 was last choice
And there is no child left so it auto generate again
And NOTHING is preventing it from 3 being 1st new choice on new list
I can think of a way how to prevent it but i will need some time
For now i will explain what is going on just so you can understand how it works
1st event if you are NOT gonna auto generate your array you can skip it
Condition is called compare 2 numbers
In 1st value i put expression VariableChildCount(Name of My Array) so in this case it is MyArray that is how i called it
I check if its equal to = 0
In 2nd value i put there is that 0 as you see
So if array have no child vars this event is executed and auto generate child variables
Trigger once so it don’t spam
Action
I am changing global var IncreaseIndex set to 0
It could be global object scene ANY variable as long as it is number i simply just went with global
Sub event of 1st event AGAIN you can skip it if you manually generate your array
Right click any event choose add and choose Repeat
That is how you get this event type
Where you see 10 is how many times i am gonna repeat whatever i want
So in this case i will generate 10 child vars so it means 10 choices
No condition here cause parent event is controlling when to run it
Action
We are adding child variable to our array variable in my case MyArray
And what we are adding is value of IncreaseIndex variable (remember in 1st event how i was setting it to 0? That is why so it always start from 0)
2nd action we change our IncreaseIndex by adding 1 to it
And all this crap works like this
Parent event
Array have 0 child vars
So add child var to MyArray with value of IncreaseIndex value
After child var is added
Add 1 to IncreaseIndex variable
And repeat it 10 times
You may wonder why it works 10 times if 1st event checks if there are 0 child vars?
Cause 1st even do in fact check are there 0 child vars after 1st is created nothing changes
for condition cause it was already triggered
Since it is triggering once it won’t spam it
So since sub event had repeat 10 times
It needs to repeat 10 times
And lastly
Since gdevelop read stuff from top to bottom
AGAIN 1st add child var with value of IncreaseIndex var
Then increase IncreaseIndex var by adding 1
And run same event 9 more times
So think of it as you just told gdevelop to read this event from top to bottom 10 times
NOW 2nd event
Space and trigger once is how i generate new random number
So for you it will be different
Action
I made scene var (again could be object or global or any as long as its number)
Called RNG
Now i set RNG var to RandomInRange(0,VariableChildCount(Name of my array) - 1)
So RandomInRange you know how works
But why why -1?
0 as lowest child index so minimum value
And - 1 cause
IF i have 4 child vars
They will look like
0 1
1 2
2 3
3 4
What it means on left 0 1 2 3 are index numbers
Imagine INDEX number as order number on list
Same as you have animations for your sprites
ALL index numbers start from 0
So if in random in range is lowest and VariableChildCount is maximum value so how many vars array have would be 4
You in this case NEVER have variable with index 4 cause 3 is highest index
Cause it starts from 0 not from 1
That is why you need -1
Cause 1st position on list is 0
Text action is there just to display whatever was picked
And last action is simply removing child by its index number from MyArray
So it DOES NOT repeat
Just so you can understand it better
Imagine my child vars instead of being numbers would be text
And i would have
0 Apple
1 Orange
2 Banana
3 Watermelon
See value is on the right but again Index is on the left
And we are picking variables here by its index
We do not specify which one exactly but randomly picking one and then removing
So if we pick 2 from
0 Apple
1 Orange
2 Banana
3 Watermelon
Then after removing that child var we will get
0 Apple
1 Orange
2 Watermelon
So Banana cannot be selected again
And same goes for case in which we have numbers as values
That wall of text should leave with no questions at least i hope
Now i am off for checking perfect solution for never repeating it even after creating new array automatically