How do I shuffle the position of instances between them.

0 favourites
  • 7 posts
  • Hi Everyone!

    I'm creating a puzzle in which you pick and drag pieces to re-arrange them into their right spot. In this case, is in a shape of a sliced up fish like so...

    All slices start in the same place but, I want to shuffle their position at the start of layout.

    I managed to use an array to set up the position of each slice but I couldn't find a way to shuffle the existing - and necessary - values within the array.

    What's the best approach for this?

    Thanks in advance.

  • You can use permutation tables feature of the Advanced random plugin.

    Create permutation table with length = Array.width

    Then in a loop for 0 to (Array.width-1) get value from Array.At(AdvancedRandom.Permutation(loopindex))

    Here is a demo, it's a bit different but may help:

    dropbox.com/s/qschy8ji3bfrvxx/PermutationRandomImages.c3p

    .

    Another option is to add a column to your array, fill it with random values and sort by this column. But it needs to be at index Y=0. So your real values will be in column Y=1

  • Thank you!

    The second option is close to what I did previously.

    Could you demonstrate on an event sheet?

    --

  • Demonstrate what? I recommend the first option.

  • I tried your solution with a permutation table but didn't really work for me.

    I did, however, had more success following this tutorial. Instead of using the width of the array as a measure, I made the variable choose between each value (Y coordinates) in that row.

    The only issue is that the some parts are being shuffled on top of each other because, some of their, are being fed the same number (Y coordinate).

    Is there a way for me to avoid this happening? Like with a variable that keeps checking if the number has been repeated?

    Thanks again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use another array to store picked random position and easily checks if array contains value:

    https://drive.google.com/file/d/1y9UrFz4h0T0riLcX89TtZLtaGhCkNyn4/view?usp=drivesdk

  • Thanks for the help!

    I'm pretty sure this is gonna be super useful somewhere along the line.

    I did, however, find out that was overcomplicating thing. I ended up not needed an array for

    this particular part.

    I ended up creating a variable with the first Y coordinate, followed by a repeat event that adds

    the height of the instance which picks a random instance and places it on that Y coordinate.

    Thanks again, guys!

    Cheers

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