Remove table rows without shifting values?

Hey, I'm having some table troubles. Working on a game, a bit like Candy Crush, but with blocks containing numbers (math game).
A random number is displayed and you have to click 2 numbers that add up to it. Overall, it's going well, but having the random sum chosen from only the numbers on the screen has been a challenge.
So, when the blocks spawn, they are given a counter number (game.number of blocks +1) and assigned a value (rdm 1-10) that is displayed. The value is assigned to a 1 column table (row=number of blocks attribute.).

So far so good...However, when the blocks are destroyed, I'd like to remove the corresponding row. But when the row is destroyed the others rows shift up, meaning the cell assigned to a particular block doesn't have the same value as it was originally assigned.

Make any sense?

I've worked around this by changing the cell value to zero rather than remove the row, but that means a lot of rows of zero near the end of the level.

To choose the sum to display my actor has to a)check if the 1st number is zero, b) check if the 2nd number is zero, and c) check if the 2 chosen cells are the same. And repeat if any of those are true.

It's a lot of cycling to choose 2 unique numbers that aren't zero from up to 100 (so far) rows. It works, but there has to be a better way!

Any ideas? Tried to keep it as short as possible, so if you need more details let me know.

Thanks!

Best Answer

  • slowcutslowcut Posts: 164
    Accepted Answer
    Hi, try to name your table rows with letters and ascending numbers
    (for example: a1, a2, a3 etc)
    if you now delete a row, the remaining rows have still their numbers and values.

    Refer to the tablecells like this:

    tableCellValue(your.table,"a"..number.attribute,column)

    the number.attribute is the attribute you have used to refer to your tablecells,
    Put your rownames in quotes (without the number)
    Seperate the two values with two dots (..)

    You can do the same with the columns.

    General think about naming all your table rows and columns in that way, to prevent unwanted

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Instead of deleting and adding rows, think of it as transferring cell values. I'm not sure why you have a single column of rows for a table structure. Usually if you are making a grid-based game you would set up the table to resemble the structure you are displaying. For example, if your game works on a 5x5 grid of blocks, you would use 5 rows and 5 columns. And then if you "destroy" a block in the game, you would change its contents to whatever should be in its place (assuming you are dropping/spawning new blocks to replace it; if not, then as you said, you can make it zero and choose to hide blocks with value zero).

    Here's a visual example:

    5 4 6
    3 4 7
    1 2 9

    If you "destroyed" the 1 and the 9 in the bottom row, you would shift the cell values in those columns down by one:

    _ 4 _
    5 4 6
    3 2 7

    Then, optionally, you would fill in the two gaps at the top with random values:

    8 4 3
    5 4 6
    3 2 7

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

  • JScottJScott Member Posts: 143
    edited January 2014
  • JScottJScott Member Posts: 143
    Thanks @tatiang for the quick and thoughtful reply. I have this table as a single column because each block is an instance of the one actor. So, it seemed an easy way to store each block's value as it was spawned (having a +1 attribute with that attribute becoming the row number). Couldn't think at the time how to do that with multiple columns! Still makes my head hurt, though I can see the logic for sure.

    The object is to clear the screen of blocks before time runs out, so although there are "n" new blocks spawned, and the others drop down, they won't be replaced indefinitely. Does that mean I have to stick to the "zero" rule?

    And if you could clue me in on shifting cell values up or down, that would be much appreciated!

    Thanks

Sign In or Register to comment.