Spawn random actors with predefined intervals
Ciaphis
Member Posts: 58
I am all set up for random spawning of two actors; I can not seem to get them to spawn in intervals (ie... first spawn, wait two seconds, spawn second actor)
Any help is appreciated!
Comments
To add bit more info:
Inhave my timers set up for each actor but what happens is the objects seem to spawn based on the first spawn instance of the actor and not from the spawn of each individual actor.
You end up with the same actor overlapping.
Inhave tried the table method outline but can’t seem to get that working properly.
If you Google spawn actor interval gamesalad you'll see some suggestions and demos for this.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
And this by @Armelline: http://gshelper.com/product/spawn-time-changer/
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks Tatiang,
I will have a look at them when I get home from work.
I googled a ton of stuff last night but I don’t think I was using the right key words.
Thanks again!!
why is it that when I set a spawn timer, it automatically spawns multiple actors of the same type? AM I missing something here?
My Spawn Actor is configured:
spawn actor: objectTop place: infront of actor
timer: 5 Run to Completion Checked.
I do not have anything in the objectTop backstage
Check to make sure you are using a prototype and not an instance of an actor. To be sure, delete the spawner actor from the scene and then re-add it. That will force it to be a prototype. Unlocked instance actors will have unique rules and it may be that that's what happened.
If not, .zip and upload the project file -- or otherwise provide a download link to it and I'll take a look.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
rule:
(optional step here if you want to spawn an actor before starting the intervals.)
spawn actor at random position.
if game.attribute 1 equals 0,
after 2 seconds spawn actor at random position.
change game.attribute 1 to 1.
rule:
if game.attribute 1 equals 1,
after 2 seconds spawn actor 2 at random position.
change game.attribute 1 to 0.
I got the actor multiple spawn issue sorted out.
Turns out, I had an additional spawn actor in the scene. -rookie mistakes-
I did manage to get the spawn leveled out but the following issues are still persistent:
Destroy command not properly killing spawned actor
Logic: if self.positionX <= -30
Do: Destroy actor
In theory, when the actor is destroyed it should not allow the spawned actor to clutter up the screen.
But that is in the premise that the timer rested after each actor spawn. Using a random timer (random x,x) be useful.
I believe, though I could be wrong, that the timer is based on the time the program has been running and not based on the life of the actor that is affected by it. Does this change if the timer is nested in the actor specific backstage or in the spawnactor.
I don't think so.
When you use a Timer behavior, it's based on the actor's self.Time value. So if you have a rule like this:
Every 5 seconds
Spawn actor
It will first spawn an actor when the spawner actor has been on the scene for 5 seconds, then when it's been on the scene for 10 seconds, etc., regardless of scene or game time.
Time is not dependent on where in the actor/layer the behavior is placed.*
*Well, if you want to split hairs, the exact moment the behavior is run will differ based on layer order but only by split seconds.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, so my questions is this, is the timer reset after the objects spawns so that it can repeat the timer function prior to spawning another object and will the destroy call negate the timer or will it only negate one single instance of the timer loop?
I could always use self.time=# instead of a timer. I will look in to doing that instead.
I might try to tackle the table method again and perhaps add a random tableRow call to add some variance to the spawning with out having to rely on the “timer” function.
Alright, this is starting to become incredibly frustrating. I am gonna post screenshots and code for what I am doing, the result I am expecting and the results I am receiving:
Below is the spawner actor object and the actor to be spawned properties. Is there anything there that I am missing?
Game Attribute added:
Att: "spawnpoint" Val: 1 Type: Index
Table: "RandomSpawn" rows: 2 Comuns: 12 (first column are set to: Text (X,Y) and the other 11 are set to: Real (X,Y positions))
Spawn actor: "spawner"
Timer: Every 2 Seconds "run to completion checked"
Nested in timer:
Change attribute: Set: game.spawnpoint to: random(1,ColCount(game.RandomSpawn))
Spawn Actor: "DualObj place: Front Layer
In the direction: 0 relative to: scene
From Position: tableCellValue(game.RandomSpawn, 1, game.spawnpoint) , tableCellValue(game.RandomSpawn, 2, game.spawnpoint)
Object to be spawned:
Actor: DualObj
Move:
Move in direction: 180 Relative to: Scene in a(n) Additive Way
At Spead: 300
The actor's self.Time attribute continually increases. It doesn't stop or reset and it's not possible to force it to do so. The Timer behavior fires every x seconds depending on what you specify. If you use an every 2 seconds Timer, it will fire 2 seconds after the actor is in the scene. So an actor placed on the scene by you will have a self.Time of 0 when the scene loads. An actor spawned onto the scene will have a self.Time of 0 when it is spawned. Two seconds later, the actor will spawn because of the every 2 seconds Timer.
If you Destroy an actor, it's rule will no longer fire. So if you have an actor with a Timer behavior and you destroy it, the Timer will no longer do anything and the behaviors within the Timer won't fire after it's destroyed.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
based on the information I proved above, what issue do you see with it?
I'm honestly a little lost as to what your question is. You asked about timers and I explained how they work. What specifically is not working the way you expect it to?
Is this still the issue?
The only thing part of your rules that included a timer was this:
That should spawn an actor every two seconds. But I suspect your issue is with actor positions... not timers. And unfortunately, I don't have time to sort through why that's not working.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It would be the positions at this point that are giving me a headache.
I am not sure if I have to have the "change attribute random(min,max)" for positions in the actor to be spawned or if I have to have them in the spawner actor.
There always seems to be at least one hurdle that I can't manage to hop when I start these projects. I refuse to let this one beat me up haha.
So my question is this:
I create a Table: RandomSpawn, then create two rows (X,Y) and then X amount of columns (screen coordinates)
Create a new game attribute: "spawnlocations" , 1, index type
Would this information be nested within the actor to be spawned or does it go in the spawner actor?
It's really up to you. I recommend putting it in the spawner actor because it's a little more complicated to sync up the spawned actor order (e.g. third spawned, fourth spawned, fifth spawned, etc.) with the table values. In the spawner actor, you would do something like what you have above. Though I did notice you had "tableColValue" when you should have "tableCellValue." I assume that was just a typo.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I scrapped the table method.
I got it to work using a simple timer and the position in the Y axis is varied as I intended; the screen clutters up fairly quick as it appears that the objects are just looping back towards the character.
I feel that the wrapper has something to do with this.
Just tested this and it's the culprit for the screen clutter. I am sure I can fix this with a location based destroy call, back to testing
Good work! These things always require a lot of testing.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Seems like I will have to follow one of the several methods for manually scrolled my a background but I want to test a loop based theory before I mess with positions and what not. I am going to have to set standard image sizes based on the largest screen that this game will be played on.
Thanks for all of the help, it has been much appreciated!
I sorted out the scene wrap X issue by spawning each background in combination with a move behavior. I tried to use the recycle method but I could not get it to work.
Next task is to dynamically adjust move speed based on either timer or based on player achievement. The later of the two seems that it would be more viable and less taxing on resources.
Was thinking about using a countdown timer to start the game instead of relying on a human input to start the game.
Thoughts?
I am also trying to use this project to learn as much as I can about this engine as possible to make sure that my sub is not wasted.
Hard to know without knowing what kind of game it is but I would err on giving the user the choice of when to start. Again, depends on the type of game.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Was thinking that an initial screen to start the game and then after player death justvhave a scene reset with a counter to start the next round.
I’m just going to assume that:
I can call another actors destroy true/false from within another actor. How it gets done Inam not certain as I would just write the call out long form and not really worry about the drag and drop menus that GameSalad uses.
I am also assuming that I am allowed to write out conditions, behaviors etc... in long form.
Are my assumptions correct?
No. You can use a global (aka game) attribute to communicate between actors, though:
Actor A
[When _______]
Change attribute game.killB to true
Actor B
When attribute game.killB is true
Destroy
No. You are limited to the drag-and-drop functionality. The functionality is extensive -- especially with respect to the expression editor -- but there isn't a way to "script" rules and then convert them to GameSalad format.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, gotcha, thanks!
Now time to add an actor attribute “ObjSpeed” pull in a rule and change self.objspeed = ### then place a timer that states every ## seconds, self.objSpeed + or - ##
This is a pretty fun program