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.

Comments

  • LovejoyLovejoy Member Posts: 2,078

    @Lost_Oasis_Games said:
    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.

    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".

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2015

    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.

  • LovejoyLovejoy Member Posts: 2,078

    @Lost_Oasis_Games said:
    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.

  • zweg25zweg25 Member Posts: 738

    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?

  • LovejoyLovejoy Member Posts: 2,078

    My above example will search every row in that particular column.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @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(....)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2015

    Ah gottcha! Thanks guys. Yeah I'm not much of a words game guy so haven't used that expression before.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @Lost_Oasis_Games said:
    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!

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Braydon_SFX said:
    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.

  • ArmellineArmelline Member, PRO Posts: 5,415

    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!

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    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.

  • mhedgesmhedges Raised on VCS Member Posts: 634
    edited September 2015

    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?

  • ArmellineArmelline Member, PRO Posts: 5,415

    @mhedges said:
    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!

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @Armelline said:
    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.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    What I am doing with it there will never be two of the same value.

Sign In or Register to comment.