More efficient way to compare one value to multiple table cell values?

JG2019JG2019 Member, PRO Posts: 3

Hi,
I'm very new to this and trying to figure it all out but am stuck on one thing so far.

I am trying to kick off some change attribute behaviors if a certain game level attribute (a user entered word using keyboard entry) is found in a certain row, columns 1-8 of a table (with 15 columns) once a certain button is pressed.

How I have it set up is a rule for when (all) the button is pressed, with a rule inside of it for when (any) the attribute is what is in the table cell value for row 1 column 1 and then for row 1 column 2 and then for row 1 column 3, etc. to then kick off the behaviors. I'm wondering if there is a way to consolidate the checking of all the columns.

Is there anyway to use Table Search or Loop Over Table or even a range in Table Cell Value instead of a singular column to make this more efficient? I've watched the tutorial on Table Search and found a little bit on Loop Over Table but nothing I am trying seems to be working. Any guidance would be great! Thanks!

Best Answers

  • tatiangtatiang Posts: 11,949
    edited May 2019 Accepted Answer

    If you need to determine if a certain value exists in ANY of the columns, use TableSearch.

    Here's an example though it's searching rows, not columns. In this case, I decided to search for the word "Unripe" in column 2 and return the name of the fruit from the same row in column 1. But for your purposes, you'll just want to check if the result of the TableSearch() function returns 0 (not found) or a number greater than 0 (found).

    @Braydon_SFX Has a good tutorial on this function here: https://forums.gamesalad.com/user/browse?keywords=192.136.254.200.

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

  • tatiangtatiang Posts: 11,949
    edited May 2019 Accepted Answer

    Oh, so sorry about the invalid link. Yes, I think that's the same video. Here's the correct link:

    https://forums.gamesalad.com/discussion/comment/452312/#Comment_452312

    The tableSearch( ) function returns the row or column number that has a value that matches (based on the type of match you choose) the search key. So no, it won't return true or false. Again, if you just want to know if ANY of the rows/columns have that value, just check for tableSearch( ) > 0.

    If you're trying to do something else, explain a bit more and I'm sure I can help

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

  • tatiangtatiang Posts: 11,949
    Accepted Answer

    Here's an example that uses a Numeric Expression to check whether or not the search key value was found within the table.

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

Answers

  • JG2019JG2019 Member, PRO Posts: 3

    Hi @tatiang ,
    Thanks for the quick reply. Just so I am understanding, TableSearch returns only the row or the column number the match is found in vs. true or false. So, I'd have to use that row/col number to equal true or false?

    Also, I am getting a "you don't have permission to do that" message from the link you sent. If it's this one:
    I have seen it and still had my questions. If it's something else, can you resend?

    Appreciate the demo. Thanks a bunch!

  • JG2019JG2019 Member, PRO Posts: 3

    Hi @tatiang ,
    Thanks for the follow up. I have it working, now. I was stuck on expecting it to return true (found) or false (not found) vs. a number value of WHERE it was found. Totally makes sense now. Appreciate your help!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome! The glossary can be of use when learning about the various functions:

    https://help.gamesalad.com/gamesalad-cookbook/1-getting-started/1-11-glossary/

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

Sign In or Register to comment.