loop over table values

hi im having abit of trouble with loop over table. i cant seem to find much resources regarding looping threw the table with a string expression to find a cell in specific column that hasn't been changed. to make more sense, ive got a table with three columns and i need to loop threw the third column. one actor will loop threw and pick an item and after that it will change the state of the third cell in the third row from zero to one. i want another actor to when touch is pressed loop threw the table and bypass all third column cells with the value of one and choose the first with zero. i think im not correctly picking the second half of statement but as there isnt any documents that i can find i am needing a bit of help. thanks for any help.

Comments

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

    You lost me here:

    it will change the state of the third cell in the third row from zero to one.

    After you find a matching cell in column 3, what should happen next? What does "the third cell in the third row" refer to?

    Sometimes, it's helpful to provide a screenshot of part of your table.

    As for the second part... use a tableSearch function. It finds the first matching cell. So if you just need the first cell with a zero, do a tableSearch using zero as the key.

    Keep in mind that whether you are looping through a table or using a tableSearch behavior, you will probably need to wrap them in a timer set to after 0 seconds with run to completion checked. Otherwise, when the touch is released (too soon), the loop/search will not have time to complete.

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

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

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

  • CMR InteractiveCMR Interactive Member, PRO Posts: 13

    I will upload screenshots of table and the rules as they are now when I’m home. I have used the loop before but only to search specific cells, I am trying to search a specific column of cells. As the loop goes threw the cells of the column I want it to pick out the first cell with the value zero. This is my problem. I think my problem is the expression as I’m using a string expression within the loop

  • CMR InteractiveCMR Interactive Member, PRO Posts: 13

    I’ve looked at that tutorial last night and it has helped but not interms if the expression needed to compare the value of the cell to what I’m searching for

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

    I understood what you wrote about searching for the first zero in a column. I thought that you were doing a separate loop/search as well but maybe I misunderstood. If all you need to do is find a zero among non-zero values, it's very easy*.

    Here's the expression I used in the attached demo:

    tableSearch( game.|T| Values ,0,"col",3,1,tableRowCount( game.|T| Values ),"exact")

    *tableSearch is the most complicated function as far as syntax goes. ;)

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

  • CMR InteractiveCMR Interactive Member, PRO Posts: 13

    I've got the demo to work now. i had the if expressions wrong. i do however have another question. the loop over table function, do i have to add anything special for the loop to end after its found its table cell, i only ask as i will have other actors using this table and loop function.

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

    Well, the Loop Over Table behavior runs from the Start Index cell to the End Index cell. So it won't stop when it finds a match. But -- huh -- what? I thought you just needed to find the first zero in a column, which would only require a tableSearch function, not a Loop.

    I also think you're going to have unpredictable results running a Loop Over Table inside an every 0.03 seconds timer, especially with Run to Completion unchecked. Make sure you test that on an actual device... not just a PC running GameSalad.

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

  • CMR InteractiveCMR Interactive Member, PRO Posts: 13
    edited September 2018

    i have two buttons with this rule attached.

    when button released
    spawn actor with green color over actor,
    loop table,
    find value larger than zero (only in third column),
    change table value of that cell to zero.

    the change table at the bottom is to allow the second button to loop threw the table and select the next cell with a value larger than 0 etc.

    i have setup display actors for the third column so i can see whats going on.
    the only problem is that the loop changes three cells at once instead on just the one that i want. any ideas?

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

    Nope, sorry, I really can't follow everything you're doing but it sounds like you're on the right track.

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

Sign In or Register to comment.