Randomize order of actors using TABLES

Hi,

I'm creating an arkanoid type game.

There is five blocks in a row, and I have 7 different blocks.

Using tables how would I be able to randomize what blocks show up in the five block rows...

https://drive.google.com/file/d/0B7NE3XRQB5t1alIwN2ZVQUlpcTQ/view?usp=sharing

This is an image of how the scene looks, I have different blocks for power ups and I need to place them in at random.

I'm not sure how to explain it more clear,
please ask for clarification if needed.

Thank you so much!

Comments

  • JapsterJapster Member Posts: 672
    edited November 2016

    I'm at work, so no GS here - Can't tell from your post whether you have a set amount of special blocks, or if you just want a random scattering of them - if the second scenario, I'd just create a loop through table behaviour, and store the results of a 'random(1,7)' into each horizontal cell as you go through the table, using the Change Table Value behaviour?

    If you're new enough for loops to be daunting, you could go quick 'n' dirty by having 5 copies of that statement just to quickly test the logic/theory first, but it's bad coding habits!

    Basically, insert a Change Table Value behaviour, select your table, choose row 1, add 5 entries (columns 1-5), each one storing 'random(1,7)' (no quotes... :smile: )...

    copy/paste the full behaviour, one for each extra row when done, and change the row value (or make a loop and use the row counter value instead, for each cycle, if you CAN use loops!)...

    for your blocks themselves, just have a ROW/COL attribute for each, and pull the value back from the table (you can increment these when spawning, if spawning)

    Conversely, you could have each block generate it's random(1,7) 'type' as the first thing it does, and if you wanted to, you could still store that to the table instead, in the row/col dictated by it's custom row/col attributes...

    Sorry about no example - always a challenge to reply when at work... :wink:

    PS - if you DID intend to just randomly place X amount of blocks, it's a different matter entirely, but in that case, I'd have a list in a table, of all positions (you only have 25? - 5 rows of 5?) each row contains 2 columns - row, col ( 1,1 1,2 1,3 1,4 1,5 2,1 etc) etc - copy the table to a temp one, then pick a table row at random (from 1,tablerowcount) for each of your 7 blocks, one at a time, use the row/col in that table row, and delete the row you picked. Repeat as needed, for however many blocks you need to randomly place, secure in the knowledge that all positions you pick will be different from any previously selected for blocks placed before the current one.... :smiley:

    There are a LOT of excellent thinkers on this forum, and will no doubt produce much easier or better ways to do this after this post, but this is a solution of sorts for you to maybe try in the meantime... :smile:

Sign In or Register to comment.