Spawning actors at specific times using tables
Hi everyone,
I have seen a lot of info on spawning random actors or spawning at random times in random locations.
What I'm looking for though, is how to spawn specific actors at specific times at a specific location.
I've created gameTime attribute that add 1 every second. I currently have a lot of rules that spawn actors when gameTime = x.
Sometimes several at the same time.
I am spawning a lot of actors and I'm thinking that using a table would be a lot neater, easier to modify and probably even lighter on resources.
I've created a table that includes my "spawn times" and x and y coordinates. In conjunction with Loop Over Table, I have a rule that says when the cell value equals gameTime to spawn the actor, but I can't get anything to spawn.
Can anyone advise if and how this is possible?
Thanks!!!
Comments
@aurynstar You can do it this way, create a table with 3 columns Time xposition and y position, put the value you want.
Create a game integer call it row set it to 1
if self.time = tablecellvalue(table,game.row,1)
Spawn actor , x position set it to tablecellvalue(table,game.row,2)
y position set it to tablecellvalue(table,game.row,3)
relative to scene
in your spawned actor change game.row to game.row +1 and thats it , there might be better solutions though
Just in case you use this dont forget to set game.row to 1 dont leave it at 0 it will cause weird behaviors in preview
@Icebox
Thanks!! Just tried it on a small scale. Works great!
Only thing is spawning the same actor multiple times at the same time. Same time is crucial as the actors actions on screen need to be in sync. As is, there is a slight delay as the rule goes through the rows.
Guess I'm missing something simple?
Do you want this to happen every time you spawn at a specific time ? or do you want it to happen once ?
what i mean is do you want to spawn 3 same actors at second 3
and then spawn only 2 actors at second 5
then spawn 5 actors at second 10
or do you want it to always spawn multiple same actors at specific time
@aurynstar Here is a quick demo using tables, im not sure if its the best method but it might help
@Icebox
Ooh! Yes! That should work!
I'll give it a try when I'm back at my comp tonight.
Will definitely update.
Thanks!!
There is a game.time attribute that already exists by default and is already counting 1 every second, it's the thing that allows the timer you are using to count seconds !
Duplicating the internal clock is not very efficient (although lots of people tend to do it). Compare creating your own gameTime with simply using the internal clock (game.time) . . .
Timer
--Every 1 second (of the built in game.time)
----change gameTime to gameTime + 1
Rule
--When gameTime = x
----Do some stuff
. . . . or more simply . . . .
Rule
--When game.time = x
----Do some stuff
@Socks
Thanks for the tip!
I created my own time attribute because I thought game.Time started when the app was opened. To control the spawn time of actors, I need time to start from zero in each level and pause when the game is paused.
Is there a more efficient way of doing this?
each actor has a self.time
@Icebox
Thanks for the demo and self.time. Totally overlooked that.
I'm just wondering though if your method would be just as resource heavy as mine?
Mine is the same, only instead of referencing a table, the time and coordinates are in the rule.
i.e.
rule
-self.time = 2
--spawn actor
x,y
--spawn actor
x,y
--spawn actor
x,y
My game was running a bit slow and I thought it was due to this?
If you dont refer to a table you will have many rules for self.time , and its easier to modify. I dont know if the slowdown is caused by this you should turn behaviors or rules on and off to determine what is causing it to run slow. I actually cant think of another method but im sure there are other ways to do it.