[Solved] Loop over table doesn't work if placed within a rule.
Hi all,
I am trying to use Loop Over Table to spawn a list of actors I store in table. I have a master actor to do this job. So when I put the Loop Over Table on master actor (not contained in within any rule), it works perfectly.
However, when I put it in a rule when master actor received touch is pressed, the Loop Over Table does not work at all.
Or when I put within a rule to check against certain attribute, it does not work too.
It only works when the actor is spawned or in the beginning only.
Does anybody have the same experience? How to solve this issue? I need to run the Loop Over Table on certain condition.
Please advise. Thank you.
Best Answer
-
tatiang Posts: 11,949
Putting a time-consuming behavior such as Loop Over Table inside of a When Touch is Pressed rule won't work because you'd have to hold down the button until the loop has completed for it to work properly. Try this:
When Touch is Pressed
Change self.startLoop (boolean) to trueWhen attribute self.startLoop is true
Loop Over TableI'm guessing you're running into a similar problem when checking for the value of an attribute... if that value changes quickly, the loop won't have time to complete. If you're still stuck, post a screenshot of your rules (upload the image to a file-sharing site and then paste/embed the link here).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
Thanks a lot, @tatiang. It works now using your answer.