GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

random/remove row

hi i am still trying to create a random enemy generator. the gist is i have 10 enemy that are different by size of arsenal, location and weapons/defenses. my problem comes when i try to randomize the enemy chosen for each game. ive included my project to randomize, even though ive set the rule to delete the chosen row and the next button press to choose only between the rows left i still get repeat rows. any help given will be appreciated.

i have 10 display boxes that shows when an enemy is choosen
also a display box to show which random number was choosen and another to show how many times the button was pressed.

Comments

  • tatiangtatiang Posts: 11,524Member, Sous Chef, PRO, Senior Sous-Chef
    edited October 5

    You were close! You're using game.enemy total to hold the value of the cell in a random row and then removing the row at index game.enemy total. That works fine for the first touch since your table looks like this:

    1
    2
    3
    4
    5
    6
    7 (row 7)
    8
    9
    10

    The problem is that once you select a random row and remove it -- let's say 7 -- your row numbers no longer match the values in their cells:

    1
    2
    3
    4
    5
    6
    8
    9 (row 8)
    10

    If you now choose row 8 randomly, you'll be removing row 8 (game.enemy total) which contains the value 9. But you're changing the table value for row 8 in table 1 which still has the value 8. Whoops!

    The fix for this is...

    tl;dr: Use a separate attribute for the random row. Like this:

    Change attribute game.enemyRow to random(1, tableRowCount(game.Table 2))
    Change attribute game.enemy total to tableCellValue(game.Table 2, game.enemyRow, 1)
    Change Table Value [table: game.Table 1] [row: game.enemy total] [column: 2] [value: 1]
    Remove Row at index: game.enemyRow

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,524Member, Sous Chef, PRO, Senior Sous-Chef

    Note that if your table and possible values were any different than sequential values equal to initial row numbers, you would actually need to use a tableSearch function for the Row value in the Change Table Value.

    So if your table was something like:

    1
    5
    8
    22
    95

    If you randomly chose row 4 with the value 22, you'd have to search for the value 22 in Table 1 in order to set its column 2 value to 1 (true).

    Hope that makes sense!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CMR InteractiveCMR Interactive Posts: 8Member, PRO

    @tatiang i have finally given your suggestions go and at first it wont work then i realised you did not constrain attribute to attribute, but attribute to cell value, worked like a charm. now ill just have to automate it in a loop and see how it goes.

Sign In or Register to comment.