Search a table and find the row/column of the searched variable?
Okay so I've been scratching my head on how to identify the row/column of a variable I find using the table search function. Since it is a network table I can't add table row headers.
Okay so I've been scratching my head on how to identify the row/column of a variable I find using the table search function. Since it is a network table I can't add table row headers.
Comments
Here is an example of how I'm using it
So in my example, I'm searching a table "TB_codes" for a key number which i have tied to an attribute since its ever changing "game.lock code" i am searching for this in a table column "col" the column number is one so "1" then the beginning row i want to start my search for that column is one "1" and the last row for the column that i want my search to end is the last one so "tablerowcount" for my table "TB_codes" and then, the key I'm looking for has to be exact in order for it to find it "exact".
That won't return me which row # the variable is in. So I know the column as all the playstogether game numbers are listed in column 1. So I need to search all the numbers in that column. I know the number I am looking for but in the end once I find the number I need to know the row number that number is in.
You can place it in a display text if you just want to see in what row/col is at, or even a change attribute if you want to store the value somewhere.
When you find the column it is in why don't you just loop through all the rows for that column until you find the variable you are looking for?
My above example will search every row in that particular column.
@Lost_Oasis_Games
The left side attribute will hold the index of the row that the value was found in, 0 if no match was found.
Change attribute self.FoundInRow = tableSearch(....)
Ah gottcha! Thanks guys. Yeah I'm not much of a words game guy so haven't used that expression before.
It's a super useful expression. You don't necessarily need to use it for word games, but dang does it make it easier!
And fast, it performs the search through all the rows in one code cycle.
I love it for spawning a game scene based off tables. You can skip all cells that are empty (in my case the cell will contain 0) and only check and spawn from the cells that actually contain something to spawn. Speeds up level spawning a lot!
Usually I have fixed points for my data and usually don't do tile backgrounds and such so first time really using it. I imagine I will use it more for multiplayer.
I don't want to rain on anyone's parade, but what happens when two rows store the same value? For example, cell 1,1 has a value of 500, and cell 6,1 has a value of 500 as well. Will GS reference the first row, the last row, both rows, or explode?
GameSalad will stop once it finds the value. This does make finding the 2nd, 3rd, 4th occurrence of values a bit more... fun!
Yep. Putting the search function in a loop makes it easier.
What I am doing with it there will never be two of the same value.