Random number, but not all numbers?

DrGlickertDrGlickert Member Posts: 1,135
edited November -1 in Working with GS (Mac)
So in my bubble shooter type game I have different color blocks and different colored shots.

So, my thought is that when all "red" blocks are gone that the "red" balls won't generate anymore.

So on my cannon the balls generate a random number before shooting (1-6). Can I make some rule that when all red blocks are gone the random number generator only generates numbers between 1-6 but NOT 2 (red)?

Is this possible? What's the best way to accomplish this?

Comments

  • msonesmsones Inactive, Chef Emeritus Posts: 75
    This is certainly very possible.

    First, you'll need an attribute that checks whether or not any of a certain color block are gone. You'll probably need one for each color. Check out this vid for more details on how to do that:



    Next, you'll need additional rules for your ball spawning. I'm going to assume you have something along the lines of "random (1,6)"; if 1, spawn blue; if 2, spawn red, if 3, spawn yellow, etc.

    Now, when red = 0 (ie, all red blocks are gone), have a rule set up in your spawn rule under the red spawn that says "if random = 2 AND red>0, spawn red. If random=2 AND red = 0, change random to 1,6"

    Now put that rule for each color, changing the "red" attribute to the correct color for each. Basically this way it'll keep changing random until it comes across a color that hasn't zeroed out yet.

    That, at least, is one way to do it - I'm sure there are others that might be better. :-)
  • hackmodfordhackmodford Member Posts: 48
    The only problem you might run into with this is timing.

    If say, you have every second random (1,6) and it generates a color that...

    Nevermind... I see you've already covered that :P
  • DrGlickertDrGlickert Member Posts: 1,135
    Anyone else have some ideas on this? I don't think this option is working for my game...
  • ValanValan Member, BASIC Posts: 410
    In a similar way, but rather than spin the random again an attribute is changed to another number. It's cheating fait a bit, but hey.

    We have blue = 1, red = 2, yellow = 3

    Random.colour= random(1,3)

    When Random.colour = 2 and red > 0 do ...
    Nested
    When Random.colour = 2 and red < 1
    Change Random.colour to 3

    This is repeated for all the co ours and the change in the last line also changes number so another colour is chosen. I just thought. A check needs to be added so it doesn't loop continue sly if all the co ours are used up.

    Hope this helps
Sign In or Register to comment.