Remove table rows without shifting values?
JScott
Member Posts: 143
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!
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
-
slowcut Posts: 164Hi, 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
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
Age of Dominion RTS for iOS
Age of Dominion RTS for Android
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
Age of Dominion RTS for iOS
Age of Dominion RTS for Android
Age of Dominion RTS for iOS
Age of Dominion RTS for Android