So in my character collection game i have a scene variable costructed as: Characters > CharacterGroup > CharacterValue
and what i want to happen is, when i click a button the children in the array, they shuffle which i tried to do using the array tools extension. But for some reason it doesnt seem to work. But when i move the array outside of the structures as its own variable, it works.
I’d like to keep the array within the structures to keep it neat so is there a way to make this work?
thank you for reading
This extension only works in a root scene variables.
What happen in your game when you shuffle the arrays?
when i check in the debugger nothing happens D:
Ops sorry. I wasn’t clear on the question. I meant what do you want to happen in your game after you successfully shuffle the arrays. I’m asking because maybe there’s an easier way to get the result you expect without using arrays.
Anyway, i did something, but you need a new variable to store the random value that will be used (in the example is the variable Shuffle)
You can put more repeat times if you want. I put 15 to have a good probability of mixing the arrays, but the minimum needs to be the number of child arrays you have, otherwise it won’t be possible to mix them all.
I don’t know if this is the simplest way to do it. But here it worked, hehe
what i originally wanted was for there to be a list of characters (the array) and everytime i click a button, the list shuffles and then picks the character at the top of the list (index 0) and creates it in the game. then that child is deleted.
i’ve done everything except figure out how to shuffle it
It might be simpler to have a number variable and just randomize its value each time the button is clicked using “RandomInRange” expression. So, the first paramater is the minimum value and the second paramater the maximum value. Example:
i did try that but, once a character was picked and the child variable had been removed, if the random number landed on the number of the variable that got deleted then nothing would happen
In my first example there is an action add a new variable before to remove. Try like I did and see if it works.
it started to work but then for some reason one time it created nothing and another it created a duplicate character
Can you show a screenshot of your related events?
here’s the array in the debugger
and idk if this helps but here’s the characters created in order LOL
I need a screenshoot of your related events. Just debugger I can’t understand what is happening
im not sure why it created 3 0’s in the array. i mean if we dont end up working this out my game will be fine without the shuffle but i just thought it’d be better with it
I’ve done this a lot. You pick a random number the size of the number of children in the array -1 because the first spot is 0. You then use the value in that location and then delete that element.
This example uses a button object named button and a text object named NewText
Because my example was before your answer I didn’t know you want delete the array. I did this:
im confused on the create object part. why is it named that?
I don’t know how are you creating your characters, but I used texts in array variable instead numbers:
And used the action “Create object from its name”:
And created in my scene a group with all characters with the name “Characters” to use in this action. That’s why is that name:
ohhh that makes sense. ill try it soon
YEEESSS it works!! thank you