Move Certain rows in table A to table B
bkhoward2001
Member, PRO Posts: 86
I have a table that has a category column and a value column... I want to copy all the rows of a particular category into a separate table... How would I do this?
Comments
I wish that feature was built in but you have two choices:
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
How would you do number 2?
Loop
Change Attribute self.counter to self.counter+1
Change Table Value [destinationTable] [row self.counter] [column 1] to tableCellValue(sourceTable, self.counter, 1]
Change Table Value [destinationTable] [row self.counter] [column 2] to tableCellValue(sourceTable, self.counter, 2]
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
You can then set conditions for the Loop (for example, start self.counter at 4 above the loop and then loop until self.counter=9 if you want rows 5 through 9 copied).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I am trying to do the first option, but it is not working.... I am using a string expression to see if the tablecellvalue IS animal, but it doesn't seem to be working.... Suggestions?
I can't give you any suggestions without seeing what you are trying to do. Post a screenshot of your rule.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I have a rule (button) that when they click on it is suppose to copy a table to a working table and then remove all rows that do not have a category of 'animal'; however, it is not removing anything...... Here is a screenshot...
Here is
a further screenshot.
It's a little hard to tell without seeing the full expressions and without knowing how your table is set up, but that looks potentially correct.
Edit: I tested it and it doesn't work. As an example, if you have this two-column table:
Name Category
----- -------
Burger Food
Tiger Animal
Cake Food
Pizza Food
Wolf Animal
And you run a Loop over Table, it will start at row 1 and delete that row, leaving you with:
Tiger Animal
Cake Food
Pizza Food
Wolf Animal
Then, row 2 will be checked and deleted, leaving you with:
Tiger Animal
Pizza Food
Wolf Animal
Next, row 3 will be checked... which means that Pizza will never be removed from row 2 because the loop counter has already passed that value.
I think the fix is to create a loop that continues until there are no more non-animal values in the table (e.g. it repeats the loop after a full pass through the table rows). I don't have time to write that all up but maybe that will help you find a way.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I am pulling my hair out but can not get this to work correctly. I am using the loop through table object.... I have a table (with columns 'Category' and 'Value'.... I want to take the table and delete all rows which have a category of 'xyz'..... What is the correct code to do this?
I have included a simple test file to show you the problem.... It is simple. In the example you have a single scene. I have two tables: the Master and the Working table. When we start, it copies the Master table to the Working table and saves. For example purposes, on the screen there are two buttons: one for the first 5 entries in the working table representing all categories. And the Category A button which should represent the first 5 entries in the working table which have a category of 'A'...... Sounds simple right? If you hover over the buttons, you should see each result respectively. Two things you will notice. First items with Category 'C' do not show up at all; second, the Category A list does not filter out any non category A items like it should. Can someone explain why this is? This Loop Through Table stuff is making no sense to me.... What did I do wrong in this example? Thanks.
Anyone?
I went ahead and merged the three threads related to this issue. Best to keep them in one place so people have a history of what's already been suggested/tried.
I don't have anything to add at this point... it would take some time to look through your project file... tables are powerful but can also be complicated to work through. And I don't have the time at the moment... sorry!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Well do you know of someone I can pay $5-10 to to take 10 seconds of their time to solve my problem?
@bkhoward2001 -- maybe the following picture will help. Please note that it is copying the rows from the master table into the working table.
@RThurman, you are a genius.... Switching the First Cell/Last Cell to Last Cell/First Cell does the trick so that the deleted rows doesn't mess up the sequence... Thank you SO MUCH! I don't know why I didn't think of that..... You are a lifesaver!
@RThurman Well, I spoke a little too soon.... When I went back to implement in main project, it still doesn't work correctly, primarily it only does the first row and never moves beyond that in the loop.... It appears that the problem occurs because the Loop Through Table is nested inside a Rule... Whenever, it is inside a rule, it seems to only apply to first record and never moves beyond.... Basically I want a button push to kick the whole thing off. Thoughts?
Yes, if you take the loop piece out of the rule it works fine, put it in the rule it only runs on first record... the rule is a simple:
if self.StartLoop =1 then do
You might try @Braydon_SFX, @jamie_c, or @gingagaming. Not sure if they do smaller projects. I generally am available, too, but this is a busy week!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang Thanks.... what I have found and it appears to be bug is:
Yes, if you take the loop piece out of the rule it works fine, put it in the rule it only runs on first record... the rule is a simple:
if self.StartLoop =1 then do
@bkhoward2001 -- your original question has been resolved, right? That is, you wanted to know how to transfer rows from one table into another. And you now see at least one way to do that right?
This new "bug" is something else right? That is, you have a condition that is going from "true" to "false" before you think it should?
What (in way the logic is set up) might be causing that?
@RThurman Yes, you previous advice works as far as getting the correct rows deleted.. but I want to have that event occur when a button is pushed, which means it needs to reside inside of a rule... When you put any kind of rule around it, it no longer works but only loops through the first record.... I know that touch or timers are not good to wrap around it and can cause troubles, so I made the button click set a variable, and then used a simple rule such as if self.process = 1 then..... I put this rule around it and now it won't work..... This is what I have discovered.... So how do you successfully get a button click to kick off the loop over table process?
It should work fine that way. Here's the demo I initially made. Based on @RThurman's suggestion, I switched first and last cell and it does what I expect it to.
Click on the green square to remove non-animal entries.
Note that it's made on a Mac but should still work on a PC.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User