Iterating through a table? Is something like a "While" loop possible?

Hey everyone! I'm pretty new to GameSalad, and after a couple of weeks of things running (more or less) smoothly, I've hit a wall. :-S

I'm creating a small tower defense game in GameSalad (you can check it out on my blog, if you want to get a rough idea: http://distractedhamster.wordpress.com/), and I've run into a bit of a snag when it comes to firing multiple cannons simultaneously.

I've created the ability for the player to build cities with cannons, which can be placed on any one of 21 squares on a grid on the right of the screen. The player can also build multiple cities (w/cannons). I've also created a table, which stores the coordinates for all cities that have been built. Every time a cannon is spawned, it creates a row in the table, stores its X-axis value in column 1, and stores its Y-axis value in column 2.

What I'd like to do now is to have the game spawn one cannonball behind each city, at predefined intervals. For example, if the player built 3 cannons, then at preset intervals (every 2 seconds, for example - using a timer) three cannonballs would be spawned; one at ( [Row1-Col1], [Row1-Col2] ), another at ( [Row2-Col1], [Row2-Col2] ), and another at ( [Row3-Col1], [Row3-Col2] ).

I've created two variables to help me: "Cannon #" and "Cannons Unfired". The basic logic that I'm thinking of would go as follows:

Timer: Every 2 seconds, set "Cannons Unfired" to "Cannon #" (Tell the game how many cannons to fire)
Rule: While "Cannons Unfired" > 0, spawn cannonball @ the coordinates: ( [Table1, Row:"Cannons Unfired", Col:1], [Table1, Row:"Cannons Unfired", Col:2] ) ---> Then subtract 1 from "Cannons Unfired". This should loop until "Cannons Unfired" = 0

Is this possible? Am I just missing a super-obvious solution here? Any help is much appreciated! Thanks!

Comments

Sign In or Register to comment.