Randomly sorting arrays

ramis2kramis2k Member, PRO Posts: 17
edited November -1 in Working with GS (Mac)
Hey fellas,

This is my problem: imagine some kind of Tetris, where you have 5 different kind of blocks, and you only get 30 blocks per level.

In my case, I don´t want to just give out new blocks randomly, but I want to set the percentage of blocks you get for each level.

What I would do in any language is to populate an array with the number of each block (1 to 5) the N times I want that block according to the percentage I set up before.
It would look something like this:

myblocks[30] = [1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5]

Once I've got my array full with the blocks percentages, I would sort it randomly so I could get a random order of a preset percentage for each block.

Does it make sense?

What could I do to accomplish it with GameSalad as we don't have arrays?

Thanks guys!

Comments

  • victorkin11victorkin11 Member Posts: 251
    GS have no array!
  • jstrahanjstrahan Member Posts: 498
    u mean ive been using arrays,game center, and pause all this time and GS doesnt have'em lol
  • victorkin11victorkin11 Member Posts: 251
    pause will be in next version, but arrays & game center..
    not sure, even GS have game center, maybe it is for pro only!
  • TwistedMechTwistedMech Member Posts: 408
    Arrays would be a nice feature. For many reasons like alien waves etc.

    You may want to look at corona for scripting.
  • victorkin11victorkin11 Member Posts: 251
    Today is last day I can get is at $99, but I saw the corona license is base on the machine, I just want to replace my 4 years old mac book pro, so I give up!
  • ramis2kramis2k Member, PRO Posts: 17
    I know we don't have arrays, that's why I'm trying to figure out a workaround for this matter :)

    Any ideas?
  • victorkin11victorkin11 Member Posts: 251
    use rule

    a=random(1,100)

    if a<50 Block = 1 (50%)
    if a>=50 and a<75 Block = 2 (25%)
    ..
    if a=100 Block =5 (1%)
  • JackBQuickJackBQuick Member Posts: 524
    I know it's unconventional, but I would use:

    Random Without Repeats (experiment)

    However, instead of having the blocks self-destruct when their number comes up, I would keep track of how many times a number appears. Only after it has appeared the number of times that you want would it self destruct. So, for instance (in your example), you would want the counter to record seven 1's before you eliminate this block.

    Hope this makes sense. Have a good weekend!
  • victorkin11victorkin11 Member Posts: 251
    oh yes! if you want to control how many different type of block you have,
    just make some attribute,

    game.blockA=5 (have total 5 block A)
    game.blockB=3 (have total 3 block B)
    ..
    ..

    then use
    x=random(1,5)

    if x=1 and game.blockA > 0
    game.blockA=game.blockA - 1 ###you get the block
    Block=A
    otherwise
    x=random(2,5) #### there is no block A

    if x=2 ....
    ..
    ..
  • victorkin11victorkin11 Member Posts: 251
    Maybe we shouldn't say GS have no arrays, but the real arrays accessed by index or pointer(very fast & easy), GS arrays accessed by if & otherwise( very slow & stupid)!
    and we don't have dynamic arrays!
  • synthesissynthesis Member Posts: 1,693
    The closest thing to an array is to use an integer actor then do some tricky math using a modulo to isolate the digit.

    Problem is...the integer can only store 8 digits and it can't lead with a zero.

    its a funky work around...but it works and I've used it to store level lock values (5 at a time instead of 1 at a time).
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    So I could do something like the following to store an actor's color in a single integer?

    Store:
    Change self.StoredColor to:
    `(min(990000,self.Color.Red*1000000))+`
    `(min(9900,self.Color.Green*10000))+`
    `(min(99,self.Color.Blue*100))`

    Load:
    Change self.Color.Red to: `floor(self.StoredColor/10000)/100`
    Change self.Color.Green to: `floor((self.StoredColor%10000)/100)/100`
    Change self.Color.Blue to: `(self.StoredColor%100)/100`

    The only sacrifice I can think of is that I can only store .00-.99 instead of the normal .00-1.00...
  • victorkin11victorkin11 Member Posts: 251
    synthesis said:
    The closest thing to an array is to use an integer actor then do some tricky math using a modulo to isolate the digit.

    Problem is...the integer can only store 8 digits and it can't lead with a zero.

    its a funky work around...but it works and I've used it to store level lock values (5 at a time instead of 1 at a time).

    I have tested, but I remember that when you type in more than 7digit, then you will have problem.
  • synthesissynthesis Member Posts: 1,693
    @Vic...
    Perhaps its 7...I couldn't remember. At some point it begins to use exponential numbers.

    @barkbark...
    game.rgbStoredColor = 9002345

    this value breaks down as the following:
    the first 9 is merely a placeholder so you can have leading zeros for the actual values...it wont be used.
    The next 2 numbers are the red value
    The next 2 are the green value
    The last 2 are the blue value

    So to assign the red value:
    self.Color.Red = (((floor( game.rgb /100000))%10*10)+((floor( game.rgb /10000))%10)))/100
    [ this assigns digits 2 and 3 to a decimal value as the red value ... in this case 0.00 ]

    self.Color.Green = (((floor( game.rgb /1000))%10*10)+((floor( game.rgb /100))%10)))/100
    [ this assigns digits 4 and 5 to a decimal value as the green value... in this case 0.23 ]

    self.Color.Blue = (((floor( game.rgb /10))%10*10)+( game.rgb %10))/100
    [ this assigns digits 6 and 7 to a decimal value as the blue value ... in this case 0.45 ]

    I think I have all the parenthesis in place...but the formulas appear to work.
Sign In or Register to comment.