How do I force a value in a set on random variables?

From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • Ok I'll try to explain this situation. I know how to pick random values for a sprite and or animation frame but How would you pick a random variable if lets say you wanted to limit or filter the values to an option - lets say their is a menu and its options are colors. I'm picking 4 random colors but when RED is selected at least one of the 4 items is RED.

    I have my sets of frames all ordered the same so lets say RED is 1-10 orange is 11-20 yellow is 21-30 etc.

    Any Ideas?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So you are displaying 4 sprites of random colors and you need at least one of the sprites to be red?

    The easiest solution is to do something like this (assuming that frame 0 is empty/transparent, and frames 1-10 are red):

    System pick random sprite
    ..Sprite Set animation frame to int(random(1,11))
    Sprite animation frame = 0
    ..Sprite Set animation frame to int(random(1,41))

    The first event will pick a random sprite and set its animation frame to 1-10

    The second event will pick remaining 3 sprites and set their animation frames to 1-40

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