Spawn set number of actors in random locations

I'm trying to spawn a specific number of actors randomly around my scene and have them not overlap. So far I've only been able to get 1 to spawn when I'm expecting 5. What am I doing wrong?

Here's the rule that I have..

- if game.SpawnAmount > 0
-- Set game.SpawnAmount to game.SpawnAmount -1
-- Spawn Actor X (random direction and random x,y positions to scene)

note, the "game.SpawnAmount" is a Game Attribute I've set to 5.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You have to use a loop. GameSalad rule conditions only trigger when the condition changes from true to false (or false to true). So if SpawnAmount is 5, then the rule triggers because 5>0 and so the condition changes from unknown to true. But when SpawnAmount goes to 4, it doesn't trigger it again because the condition is _still_ true. It hasn't changed value.

    For an example of looping methods, grab my demo attached here: https://forums.gamesalad.com/discussion/comment/364679/#Comment_364679

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Also, if you want to avoid repeat locations, you can destroy a spawned actor when it collides with itself. I would do the following:

    When actor collides with [same actor] AND self.time=0... destroy [this actor] and change attribute game.SpawnAmount to game.SpawnAmount+1.

    Hopefully, the self.time=0 condition would cause the newly spawned actor to be destroyed while keeping the existing actor that was already at the location.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • OrbInteractiveOrbInteractive Member Posts: 14
    I'm studying your looper project, but confused with a few things. I guess my first two questions are..
    1) How did you create the game attributes "Counter" and "MaxIterations" as "indexes"? I don't have the index option.
    2) How are these indexes being set to a value of 500?
  • PixelMetalPixelMetal Member Posts: 283
    I'm studying your looper project, but confused with a few things. I guess my first two questions are..
    1) How did you create the game attributes "Counter" and "MaxIterations" as "indexes"? I don't have the index option.
    2) How are these indexes being set to a value of 500?
    1) If you're on Windows, there's no index attributes. Use integer instead.
    2) Set it manually.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You can use integers if you are using the Windows version of Creator. It works the same as with index (0, 1, 2, etc.) attributes.

    The loop condition is set to stop at a counter value of 500 but you can set the rule to stop at 5 or any other value.

    If you search the forums for iterative loop or timers are for chumps (see the very last few posts) you'll see more info about how loops work in GameSalad. I'm on my phone, otherwise I'd provide the links for you.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • OrbInteractiveOrbInteractive Member Posts: 14
    Notes...
    1) Ok, ya I can't see the value of your index attributes, apparently a bug with PC/only supported by MAC.
    2) Both the Every0 and TimeStamp loop from your example project use time as the condition changer(?). One using a Timer the other a Rule that checks/compares time which you will compare as false for .005 seconds before coming true again..Slick!
    3) AH! *bonk to head*, your spawn looper setup is pretty much the same as mine. BUT, you are spawning the same actor as the Spawner. So, each actor that spawns will evaluate the rules and spawn another.

    Live and learn. ;)

    thanks for the help fellas.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Sorry... let me know if you need screenshots of anything.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    Also, if you want to avoid repeat locations, you can destroy a spawned actor when it collides with itself.
    Excellent idea, consider it stolen !

    : )
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @Socks Awesome! I see the GameSalad community as a sort of living organism with many brains. You'll probably take that idea in directions I've never considered, which will spawn off some other idea by some other talented developer around here and a few months from now I'll benefit by reading some amazing discussion thread about something new you can do with GameSalad.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    @Socks Awesome! I see the GameSalad community as a sort of living organism with many brains. You'll probably take that idea in directions I've never considered, which will spawn off some other idea by some other talented developer around here and a few months from now I'll benefit by reading some amazing discussion thread about something new you can do with GameSalad.

    Yep, agreed, put stuff in, watch it evolve, when it produces something useful then steal it !

    : )
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @Socks Awesome! I see the GameSalad community as a sort of living organism with many brains. You'll probably take that idea in directions I've never considered, which will spawn off some other idea by some other talented developer around here and a few months from now I'll benefit by reading some amazing discussion thread about something new you can do with GameSalad.

    Yep, agreed, put stuff in, watch it evolve, when it produces something useful then steal it !

    : )
    That's the spirit!

    Cast your note-in-a-bottle into the GameSalad sea. Then one day watch it drift back to you all bejeweled with the beautiful barnacles of others' additions. Dry it out. Give it a good coat of lacquer. And display it as the candle holder it was always destined to be!

    (Jeesh -- I have no idea where that came from!)
  • SocksSocks London, UK.Member Posts: 12,822
    Cast your note-in-a-bottle into the GameSalad sea. Then one day watch it drift back to you all bejeweled with the beautiful barnacles of others' additions. Dry it out. Give it a good coat of lacquer. And display it as the candle holder it was always destined to be!

    (Jeesh -- I have no idea where that came from!)
    Lol : )

  • schezanmschezanm Member Posts: 1

    I am not able to respawn my actor
    I've used timer
    everything else is fine as I am following a youtube video
    the problem i think can be possible is different co-ordinates
    and to be honest I am a newbie
    can anyone please spare their precious time and help me troubleshoot this issue ? thank you.

Sign In or Register to comment.