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!
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
You are on the right track. You just need a second 0 second timer within your
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Hope the attached file helps. You can place cannons, their positions then save to a table. These cannons then fire every 2 seconds.
p.s.
Not a necessity, but maybe consider changing your 2 second continuous Timer to a Rule based on "game.Time" as in the attachment. It is a little less taxing on the system.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
To get them in sync you will probably have to place a triggering rule in each of the cannons based on an aforementioned game.Time rule.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
But still - the effect is pretty convincing, even with the slight delay. Even so, I'll definitely be looking into working out a more elegant solution. My original idea revolved around using game.Time, but I was having some trouble getting that up and running... Perhaps I'll take another stab at it tomorrow, when I'm a bit more awake. :-P
Thank you for your input and encouragement! I'll definitely be looking over everything and reevaluating in the morning.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Considering your "6 games in six months" time schedule, waiting for the new loop behaviour to be released for Windows may not be an option.
Secondly, the loop behaviour will also cause the slight delay between each cannon firing, thus preventing your goal of all cannons firing in unison. The new loop behaviour only completes one cycle per frame draw.
If you look at the code in my last posted attachment (SychronizedCannons), that is probably still your best option under the circumstances. And, it is just as much code as the new loop behaviour will be, except for one extra game level attribute.
You should be able to unzip and open it in your windows creator just fine, I checked.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com