How do I write the Logic to have the computer pick 3 color images?

0 favourites
  • 5 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.
  • Hello Form:

    I have a query referring to random image selection.

    The computer logic is tasked with picking 3 color images: Red Blue and White.

    Three images have to be chosen but the Red image needs to be in EACH group.

    Example: Red Green Pink

    Purple Red Yellow

    Orange Brown Red

    It does not matter where the Red image is positioned just that the Red Image appears in each group.

    Does anyone have any ideas? Thanks

  • If it doesn't matter where Red is then you can start with Red and pick 2 other colours right? The problem here is not picking the same one twice which I usually resolve with an array. You can push all colours into an array and select one at random, then delete the row so it's not picked again. Then select another one at random.

  • Thanks for the REply. I'm making a Game for Autistic Children wherein they try to find the image (out of a set of Three images) that has Red in it. The Game would work better if the Red image would move like this:

    Red Blue Green

    Pink Yellow Red

    Brown Red Gray

    As opposed to Red White Orange

    Red Green Blue

    Red Violet Teal

    The array sounds good. I just need to find a way to make sure the Red image is always included in every group of three images

  • Cool, so it does kind of matter where the Red is then :P You can combine some kind of logic. choose(0,1,2) would give you a random selection to give to Red. if Red is 1 then it appears in the middle for example. You can combine that with a function or loop that you run with a counter that repeats 3 times. So a global variable set to choose(1,2,3) with a separate counter from 1 to 3, if counter = gv, then add Red, else pick a random colour from the array.

    Maybe look something like :

    set gv to choose(0,1,2)

    for (loop) 0 to 2,

    if loopindex = gv add "Red"

    else, run the search through array for a random colour

    output would be 3 colours, none the same, with red included at a chosen position (the global variable)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • plinkie

    Thanks for your assistance.


    I use 2 arrays (One with all Red images = One with all the other Color Images). This way I can get a Red Image in Every 3 Image set. This works.

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