Pick a random sprite without picking the same again

0 favourites
  • 6 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hey.

    I've been doing a card deck game and ran into a problem. I have 8 spots where random cards a generated on. If you click on a button every CardSpawn should get a random card.

    Code wise I have something like this:

    i.imgur.com/adsN7AI.png

    Though quite often the system picks the same cards (I think because all happens on exactly the same time) and it happens that I only have 4 or 5 or 6 cards on my spawnSprites and not 8.

    Is there any better way to choose random cards without duplicates?

    Regards,

    Kraudi

  • Yes. You can create an instance boolean and set it to 'true' when the card was picked. Then add the condition 'is boolean not true' under 'pick random'. Find out where and when you can reset that boolean.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes. You can create an instance boolean and set it to 'true' when the card was picked. Then add the condition 'is boolean not true' under 'pick random'. Find out where and when you can reset that boolean.

    Thanks. I've tried but it is only done with 1 card on each click. I've set the boolean to false when an card arrives at their destination.

    i.imgur.com/Mxtag6y.png

  • Push all available cards into an array, then pick a random one out of it and delete that row from the array so it cannot be picked again.

  • sometimes it is not obvious, but when i put the 'Picked=0'-condition above the 'pick random'-condition it seems to work:

  • sometimes it is not obvious, but when i put the 'Picked=0'-condition above the 'pick random'-condition it seems to work:

    This seems to work without the boolean after I tested it a couple if times. Hope it works stable:-D Weird but okay I take it :-D

    Thanks for the solution. I got angry because I couldn’t get it to work :-D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)