I know that similar questions have been asked before, but I’ve been looking for several hours and tried using arrays, and I still can’t figure out how to solve my problem. I am making a card game in which a random card animation is generated when a button is pressed. I need it to generate a random number (0-51) without repeating. How would I do this?
Add the Array Tools extension to your game. Create an array of the 51 number. Shuffle the array, and then either use the Shift array child with index 0, or pop array child.
So populate it this way:
and get the next animation with a pop:
![]()
or with a shift:
![]()
Thank you, and what would I write for the card animation? Right now, I have something along the lines of “change the number of the animation of PlayingCard: set to ________” What would I put in the blank?
You’d use the variable “SelectedAnimation”, or whatever variable you use to store the animation number pulled from the array.
That “Remove first child” is in the beginning of scene, so only gets run once. Put it as a subevent of the “Green Button is clicked” event.
Are the cards images all separate animations, or do the cards make up all the frames of one animation?
If it’s the latter, set the current frame of the animation to SelectedAnimation:
![]()
How do you know a new card get created? Is the space where it’s generated blank and then the new playingCard object placed in the scene? If not, is the value of HitButton = 1? If it is, then it’ll be an action elsewhere that’s interfering or changing the card animation.
That helps a lot, and I understand what you’re doing.
You need to use the “Remove the First child...” action before you set the animation of each card.
As it stands, you set SelectedAnimation once and then use it multiple times. You need to set it every time you use it if you want a different value with every usage.
Ok. Do you have a scene variable named SelectedAnimation? If so, delete it.
I only have a global variable named SelectedAnimation.
I can’t see anything that jumps out from the screen shots. Any chance you zip up your game and make it available on a shared drive for download so I can see what’s going on? PM me the link if you like.
I messaged you the link to my game.
Got it. I’ll download and check when I’m not at work.









