My actors keep spawning on top of each other

gama3gama3 Member Posts: 29
edited December 2015 in Working with GS (PC)

I've been working on this random grid spawner for a few days and I'm getting it pretty dialed in, but now I'm running into a few unexpected problems.

For some reason, actors are spawning in on top of each other, which is not the desired outcome. My program should make it so that each actor spawns in at a different coordinate, for a total of 8 actors on the screen at any given moment.

I'm not sure if the problem exists because I am asking the program to do too much at a time, or if there is some sort of syntax error on my part?

Any help would be appreciated with this, and I would like to say that this forum has been very helpful with offering advice!

Here is my project: All the spawning code is located in the actor 'Spawner'

http://www.mediafire.com/download/i8n61a6qq9x8cco/gridspawn2.zip

edit: Also there is some crucial code located in the 'good' and 'bad' actors as well.

Comments

  • crestwoodgamescrestwoodgames Member Posts: 191

    Are you trying to spawn 5 of each color? I am a bit confused as to what you are trying to do. The code looks a bit off, not sure thats how I would do it.

    What exactly are you trying to do?

  • crestwoodgamescrestwoodgames Member Posts: 191


    This will get you 3 red and 5 white in random locations without spawning on top of each other. Not sure if this is all you needed. I used local variables vs global inside the spawner

  • gama3gama3 Member Posts: 29
    edited December 2015

    Yep, I'm trying to get 3 red and 5 white. Do you know why my actors were spawning on top of each other like they were?

    Also, how do you distinguish between local and global variables?

  • crestwoodgamescrestwoodgames Member Posts: 191

    I use the term Local to define a variable within an actor itself. A Global/Game variable are the same thing, and are "seen" by everything in game. If you only have a few game variables its OK, but try not to use them if you can.

    As far as your issue, I did no have much time to dig into it. But, if your were spawning on top of each other, that row was not being removed properly. I think the Red rules were conflicting with White.

  • gama3gama3 Member Posts: 29

    Alright, I'll try using fewer global variables then and see if it changes anything. (I have quite a few at the moment.)

  • gama3gama3 Member Posts: 29

    Also is it possible for you to send me your game file so I can look a bit closer at your rules? It's hard to see the details with the screen captures. @crestwoodgames

  • ArmellineArmelline Member, PRO Posts: 5,365
    edited December 2015

    You have a few things going wrong. I don't think that they're spawning on top of each other, you're just not spawning the correct number. However, it may be both!

    You seem to be wanting 5 white actors. However, you have the white count attribute incrementing by 1 before the actors are spawned. When combined with your < 5 rule, you're never going to get to 5. You want the actors in each loop to be ordered like this:

    Pick random location
    Spawn actor
    Remove table row
    Increment spawn count

    Same for the red. Since you're running two different loops, it you in theory have the order things are done messed up. I'd suggest putting both in the same loop. The two loops have the exact same conditions anyway.

  • vikingviking Member, PRO Posts: 322

    If you are not sure if you are indeed spawning actors on top of each other then I have a useful trick to be 100% sure. Simply add a display text behavior in the actor that uses for example random(-32,32) in the Y position box. That way you will clearly see if you have more than one actor on top of each other as you will see multiple texts displayed.

Sign In or Register to comment.