How do I pick multiple instances randomly ?

0 favourites
  • 10 posts
From the Asset Store
Pick Up Items Sounds
$3 USD
50% off
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hey !

    i know that there is a lot of subjects about it but i didnt find my solution.

    I have 4 towers who spawns bullets each second.

    But i want to pick two of them at start of the game, randomly.

    I tried to use " pick random instance " and duplicate it two times.

    But sometimes, the same one is selected two times.

    So, the game pick only one tower.

    How can i force the game to pick two different ones ?

    thanks !

    Tagged:

  • You could have a variable on the tower to tag that it's been chosen then when you say pick a random instance set the variable to true, and each time pick a random instance where the variable is set to false.

  • Another way that is useful in some situations is:

    For each sprite ordered by random(1)

    — do stuff

    — compare: loopindex=1

    — — stop loop

  • Does the random(1) here mean that it will go through that loop twice? (Since it starts at 0) I didn’t know that there was embedded logic in the Pick Instance that carried loop counts, I would have though you had to call a loop for that

  • The random(1) expression causes the “for each ordered” to loop over the instances in a random order. The loopindex is 1 when it’s on the second instance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another way that is useful in some situations is:

    For each sprite ordered by random(1)

    — do stuff

    — compare: loopindex=1

    — — stop loop

    i dont understand that as " event system "

    compare what ?

    if i compare is my boolean is true, when it picks randomly, it can pick the same one.

    It doesnt spawn a sprite, but the same tower is picked

  • It’s system->compare two values

    With loopindex as the first value and 1 as the second.

  • Play with random suggested by ROjO: dropbox.com/s/q9stpe76oip69yn/loop_random_slider.capx

    [Warning ~ it will hipnotize your eyes]

  • It’s system->compare two values

    With loopindex as the first value and 1 as the second.

    I am very dumb.. even with the exemple.. sorry :'( i cant understand

    can you make an exemple with my situation ?

  • Have a look: dropbox.com/s/lsff0sd6fu4awuw/random_spawner.capx

    So in the example I disabled pick random instance and use what sugested by ROJO. Feeding for each ordered by random 2 loops iteration to get 2 random instances (loopindex 0 to loopindex 1). So if you want to pick 3 random instances change random value & loop comparison to 2.

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