Spawn, sometimes not Spawning?
![thepositivemoxie](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
Hey all, my game is coming close to an end, and I have one thing left I am struggling to understand. I essentially have 3 spawn points that move acrossed the screen, when it exits the screen it resets the nextShot value back to 0, so when it is in the correct spot it can run the code and begin spawning out random actors at set intervals. I have tried every way I can conceive, from using Timers, Interpolate, and recordering self.time as well as real devices clock time, then asking if it was larger then its original by the right time. None have worked to solve this issue. Basically I am asking it to spawn out 3 objects, every 2, 4, 6 seconds. Then after 9, reset, and randomize the objects that come out and repeat. It works only SOMETIMES though. Not sure why. Very hung up on this. It usually shoots out 3 for 2-3 times, then will not shoot out the first one (long lag time), then shoots out the other two. Seems pretty random though. Below is the code, maybe a little lengthy, but I wrote it out exactly how it is in my rule sets. If you have any suggestions, I would looove to hear them. Would be very grateful, as I have worked on this problem for about a week and a half now. It's tiring!
I have a table, with 6 rows, and 3 columns, calling the random numbers for when it should shoot.
1,2,3
1,3,2
2,1,3
2,3,1
3,2,1
3,1,2
RANDOM SPAWN POINT(Rule)
if self.nextShot = 0
DO ->
Change Attribute
Set: self.randomCell
to: random(1,6)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 1)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 2)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 3)
Timer
After > 1 Second (Run To Completion)
Change Attribute
Set: self.nextShot
to: 1
--------------------------------------
In Shot Range (Rule)
if SpawnLeft.position.x > 90
if SpawnLeft.position.x < 1190
if SpawnMiddle.position.x > 90
if SpawnMiddle.position.x < 1190
if SpawnRight.position.x > 90
if SpawnRight.position.x < 1190
if self.nextShot = 1
DO>
Change Attribute
set: scene.shotRow
to: self.shootColumn1
Timer
After > 2 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn1
Timer
After > 4 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn2
Timer
After > 6 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn3
Timer
After > 9 seconds
Change Attribute
set: self.nextShot
to: 2
---------------------------------------
if self.nextShot = 2
DO>
Change Attribute
set: self.nextShot
to: 0
I have a table, with 6 rows, and 3 columns, calling the random numbers for when it should shoot.
1,2,3
1,3,2
2,1,3
2,3,1
3,2,1
3,1,2
RANDOM SPAWN POINT(Rule)
if self.nextShot = 0
DO ->
Change Attribute
Set: self.randomCell
to: random(1,6)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 1)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 2)
Change Attribute
Set: self.shootColumn1
to: tableCellValue(game.shotOrder, self.randomCell, 3)
Timer
After > 1 Second (Run To Completion)
Change Attribute
Set: self.nextShot
to: 1
--------------------------------------
In Shot Range (Rule)
if SpawnLeft.position.x > 90
if SpawnLeft.position.x < 1190
if SpawnMiddle.position.x > 90
if SpawnMiddle.position.x < 1190
if SpawnRight.position.x > 90
if SpawnRight.position.x < 1190
if self.nextShot = 1
DO>
Change Attribute
set: scene.shotRow
to: self.shootColumn1
Timer
After > 2 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn1
Timer
After > 4 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn2
Timer
After > 6 seconds
Change Attribute
set: scene.shotRow
to: self.shootColumn3
Timer
After > 9 seconds
Change Attribute
set: self.nextShot
to: 2
---------------------------------------
if self.nextShot = 2
DO>
Change Attribute
set: self.nextShot
to: 0
Answers
Create a timer that iterates EVERY "1" second. In the timer add an integer attribute that is titled "SpawnTimer" or something like that. Have it iterate by 1 each time:
spawntimer = spawntimer + 1
have a rule inside the timer that says
--------
if spawntimer =10
then spawntimer=1
--------
This will reset your counter for your timer
Outside of the timer, just use spawntimer as your rule for doing whatever it is you need to do.
If spawntimer = 2
Then do something
If spawntimer = 4
do something else
The issues I have had with timers are, for the most part, figuring out when they are going and when they are not. Depending on where you put them, they may, or may not, reset, or do what you ask. I think it might be better to just run the single timer the entire time and have a variable keep track of your information.
I hope this helps!
Charles