Nested Loops? (Specifically Looping Over a Table)

So I just fired up GameSalad after a while of not touching it, and I felt like maybe messing with the (relatively speaking) new loop behavior container. More specifically, I was gonna attempt using nested loops along with an array (or table if you wanna use the fancy Gamesalad terminology) to set up a mockup kind of tiled pattern if that makes any sense. Basically my problem is that when attempting to make a nested loop, I don't get any feedback when testing. There's no infinite looping to my knowledge (I dunno if GameSalad does something to prevent itself from crashing but I'll assume it doesn't) and when I don't use a nested loop, it seems to work fine when I was logging debug statements. Here is a screenshot of what I currently have. (Actor 1 and Actor 1 copy are just different colored squares I was using to make sure it was responding correctly to the different table cell values). I am currently using the most recent version of GameSalad (1.25.80) Let me know if you need any more information. Thanks!
s847.photobucket.com/user/adscomics/media/Screen%20Shot%202017-08-24%20at%209.17.26%20PM_zpsnwt1dqlg.png.html

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited August 2017

    @ADSentertainment,

    look at the info panel next to the loop behavior in the behavior list. There it tells you that you can't use a loop inside a loop.

    To work around this, use one loop, and increment the row and column attributes inside it.

    Something like this (assuming a 10x10 array):

    Change Attribute: self.row to 1
    Change Attribute: self.col to 1
    
    Loop
    While self.row <= 10 
    and self.col <= 10
    
             ... do what ever ...
    
             Change Attribute: self.col to self.col + 1
    
             Rule: If self.col > 10 then 
                     Change Attribute: self.row to self.row + 1
                     Change Attribute: self.col to 1
             End Rule
    
    End Loop
    
  • ADSentertainmentADSentertainment Member Posts: 397

    @Hopscotch
    I see! That makes sense since you can check for multiple things at once in Gamesalad. Thanks!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881

    @Hopscotch just beat me too it. But here is an example that I just stuck in the spare code thread. It might work for you:
    http://forums.gamesalad.com/discussion/comment/599873/#Comment_599873

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited August 2017

    @ADSentertainment

    an alternative shorter and more lightweight method (again assuming a 10x10 grid):

    Change Attribute: self.counter = 0
    
    Loop
    While self.counter < 100
    
             ... calculate the column as mod(self.counter,10)+1
             ... and the row as floor(self.counter/10)+1
    
             Change Attribute: self.counter = self.counter + 1
    
    End Loop
    

    @RThurman :)

  • ADSentertainmentADSentertainment Member Posts: 397

    @RTHurman Thanks! I'll definitely look into that!

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @RThurman

    looking at your linked project - we are going to have to put the thumb screws on GS to keep that inline binary logic alive in the new HTML5 creator. Currently its strict and predictive syntax checking does not allow for it. Same for a lot of useful LUA functions, like match, gsub, etc, and pattern matching.

  • ADSentertainmentADSentertainment Member Posts: 397

    @Hopscotch @RThurman Got it working, thank you all so much! I haven't used the more lightweight one yet but I'll look into it more at some point.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881

    @Hopscotch -- good point! It would be a shame to loose such a powerful tool as binary logic in the expression editor.

  • ADSentertainmentADSentertainment Member Posts: 397

    @Hopscotch regarding your more lightweight method, where it says while self.counter < 100. Is that 100 coming from multiplying the column count and row count of the grid/array since it's a 10x10 grid?

  • HopscotchHopscotch Member, PRO Posts: 2,782

    Yes @ADSentertainment, that is correct. I could have been clearer about it. :)

Sign In or Register to comment.