Using a table in a loop
sevek
Member, PRO Posts: 30
Hi guys.
So, I have this table.
...which contains 9 different Y-axis coordination.
Now, the first actor is spawned based on row 1, (90 pixel on Y-axis),
the second actor is spawned based on row 2, (110 pixel on Y-axis),
the third actor is spawned based on row 3, (130pixel on Y-axis).
... and so on. You get the point.
Now, I can individually spawn them, but that seems really inefficient. Especially since I want them to loop back to row 1 when the last row is used.
Any suggestion on how to write a rule so that y-axis coordination on row is used from the top to bottom and loop back to the first one?
Thanks!
Comments
Hi @sevek Try the following:
Make an integer attribute, call it Count, its value at the default zero. I think you've got the spawning in a Timer behaviour? If not, just don't use that and add your own triggering method you're using.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thank you Gyroscope once again!
I think I am understanding your logic.
Thanks!
@sevek
In addition to the excellent approach that @gyroscope gave, there are a couple other ways to do it.
1)
Make an index attribute.
Timer every ? seconds Change Attribute: [ self.index ] To: [ (self.index %9)+1 ] Spawn actor -- position↑: [ tableCellValue(game.Table 1, self.index ,1) ]
2)
You don't need a table when the values go up by 20 every time. You could --
Make a 'yValue' attribute.
Timer every ? seconds Change Attribute: [ self.yValue ] To: [ max(90,(self.yValue %250)+20) ] Spawn actor -- position↑: [ self.yValue ]
Thank you! @RThurman .
I will try that method as well!
Appreciate it!
@RThurman
Hi.
So I got it working using your method.
Just quick question.
What does "%250" do? what is the logic behind this?
Thanks bunch!
@sevek
The " % " sign indicates a modulo operation. (You might want to look up what modulo is/does.)
Perhaps a better way to write the expression is:
max(90,mod(self.yValue+20,270))
This form of the expression uses modulo the way GameSalad documentation wants it done.
And to add, @sevek , to add to @RThurman's excellent advice, GameSalad is going to depreciate the % eventually and I think it was @CodeWizard recently who recommends the mod expression be always used instead now.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thanks guys!
That really helped me to understand the concept!
I have progressed so much further with you guys help!
You are welcome!