Avoid repetion in random combinations

1 favourites
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • The end result is pretty much the same for either shuffle. I'm always on the look for a simpler way to do it.

    You can do that rearranging with just text like so:

    listA = "DCAB"
    listB = "3142"
    listC = ""
    
    start of layout
    repeat 4 times
    -- add mid(listA, find(listB, str(loopindex+1)), 1) to listC

    To do it with picking sprites it would be tedious. You can convert a row of sprites to text with:

    list = ""
    
    start of layout
    sprite: group=0
    for each sprite ordered by sprite.x
    -- add str(sprite.animationFrame) to list

    or you can use one of these in the add to list action if you want named frames

    mid("ABCD", sprite.animationFrame, 1)

    mid("1234", sprite.animationFrame, 1)

  • The end result is pretty much the same for either shuffle. I'm always on the look for a simpler way to do it.

    You can do that rearranging with just text like so:

    listA = "DCAB"
    listB = "3142"
    listC = ""
    
    start of layout
    repeat 4 times
    -- add mid(listA, find(listB, str(loopindex+1)), 1) to listC

    To do it with picking sprites it would be tedious. You can convert a row of sprites to text with:

    list = ""
    
    start of layout
    sprite: group=0
    for each sprite ordered by sprite.x
    -- add str(sprite.animationFrame) to list

    or you can use one of these in the add to list action if you want named frames

    mid("ABCD", sprite.animationFrame, 1)

    mid("1234", sprite.animationFrame, 1)

    Thank you very much! This command to generate the lists is very useful but I think I don't know how to use it correctly. I spent all morning trying to implement it so I could only say thank you, but I couldn't.

    I have to cross two pieces of information to be able to find the third.

    The situation is like this:

    1) I have the 4 letters being generated randomly and being displayed in 4 instances of sprite1 (eg DABC). The list of frames is stored in the variable seqLetters (3012)

    2) I have the 4 numbers being randomly generated and being displayed in 4 instances of sprite2 (eg 4132). The frame list is stored in the seqNumbers variable (3021)

    Problem:

    Now I have to show the result in the 4 instances of sprite3, positioning each letter present in sprite1, in the position determined by sprite2 (ex. CDBA), that is, first the letter of position 4, then the letter of position 1, then the letter of position 3 and finally the letter of position 2)

    I'm using the first command block you suggested, but I can't get the result.

    repeat 4 times
    --add mid(seqLetters, find(seqNumbers, str(loopindex+1)), 1) to seq
    
    for each sprite3 order by sprite1.X ascending
    -- set Animation Frame to int(mid(seq, loopindex, 1))
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dropbox.com/s/9xmf8rhsypwojxf/shuffle_and_reorder.capx

    Thanks for the example.

    This or something similar I already managed to do :)

    What I need is to use the frame numbers to identify each letter position. This is the correct result:

  • for each sprite3

    pick sprite2 instance loopindex

    pick sprite1 instance sprite2.animationFrame

    -- sprite3: set frame to Sprite1.AnimationFrame

  • for each sprite3

    pick sprite2 instance loopindex

    pick sprite1 instance sprite2.animationFrame

    -- sprite3: set frame to Sprite1.AnimationFrame

    Very nice! Thank you.

    As I only had the variable storing the numbers, I ended up generating a temporary sprite to be able to list these numbers. Curiosity: is it possible to do it with a variable instead of using the sprite frames as a reference?

    Thank you very much. Providing some coffee. ;)

    I will create some difficulty levels and I think I will be able to implement it using the solutions you gave me.

  • If you setup the variables with different values, sure.

  • Hi R0J0hound

    I tried to solve this problem but I've been stuck in this trap since Thursday.

    This is the file I'm using to test the possibilities.

    At first, I need to change the position of the letters below, according to the black numbers below (above the letters). The answer is generated before the script and available on one of the buttons with orange numbers (3 in total). Could you please check why my code is not working? Thanks.

    we.tl/t-LzcJQJ3wGP

  • Hi,

    I had a look, but I honestly don't understand what the correct behavior should be.

    I see a row of letters, five rows of numbers, then another row of letters. What is the significance of each row? what should be shuffled? what should be unique from others? what is used to reorder another row? I'm honestly fairly confused what should be going on.

  • Sorry about that R0J0hound

    I know it's confusing and I should have left an explanation.

    This is what I already solved.

    Now I need to solve these two and I'm not able to do that (the same 2xC3P layouts)

    Layout 1

    Layout 2

    C3P: we.tl/t-16w3i8PPXy

    I hope I managed to make it more understandable now. If not, please let me know. Thanks

  • Ah. I think that makes sense. The logic would roughly be this then. You just need a way to shuffle a list, and rearrange a list with another list.

    LettersA = shuffle(abcd)
    
    While
    — Choice1=shuffle(1234)
    — Choice2=shuffle(1234)
    — Choice3=shuffle(1234)
    — if choice1!=choice2 and choice1!=choice3 and choice2!=choice3
    — — stop loop
    
    Correct = choose(choice1,choice2,choice3)
    
    Black1 = shuffle(1234)
    
    LettersB = shuffleBy(lettersA, correct)
    LettersB = shuffleBy(lettersB, black1)
  • Thanks for replying, R0J0hound

    I think that now I could not follow your reasoning. It's so simple that I can't decipher it :) Which example does this code apply to? I was previously using temporary sprites to be able to realign the frames correctly. I saw that here you are not using it. Could you please explain a little more?

  • It’s just an overview of how to do it.

    Previous capx show ways to represent the numbers as sprites or variables, ways to shuffle the values, and to reorder one list with another. They are building blocks to do the rest.

    I tend to break things down into general chunks like that otherwise I get lost in all the details.

    It will take a few days to get time to implement it.

  • No problem.

    I had tried doing this for layout 1 example but it didn't work and I can't even imagine why.

    I will keep trying

  • Yeah, even though I provided the ideas in that screenshot I'm confused by what it does.

    Here's a capx of that pseudo code I posted. To simplify things It uses variables, and functions to organized the steps. The sprites are all the same type and are set as the last step. Again, that was to simplify things and need less events.

    dropbox.com/s/n3ewz0wklyzh26w/shuffle_and_reorder2.capx

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