Random Actor Spawn at set locations on screen using tables

hillsthillst Member, PRO Posts: 3

Hi All,
I have been playing around with GS for a little bit now but have been stumped by a recent set of rules I was trying to setup. I have 3 actors that I want to spawn over the screen in rows. No actors can overlap and want at least 1 of each type of actor on a particular row. I'm using a table currently for positions but i keep having actors placed on top of each other or areas where no actors have even spawned. The table has X,Y positions that correspond to all possible positions on screen that need to be filled up by any of the 3 actors. Basically here is the code:

Self attribute - actor1index
Self attribute - actor2index
Self attribute - actor3index

Loop until no rows in table left:
*change attribute "actor1index" to random(1,3), similar for the others "actor2index" and "actor3index" ensuring they are unique/not the same.

 *spawn actor 1 @ row(actor1index)
  spawn actor 2 @ row(actor2index)
  spawn actor 3 @ row(actor3index)

 *Delete rows @ indexes "actor1index", "actor2index", "actor3index"

  Repeat above until Loop identifies that there are no more rows.

Does anyone have any idea what might be going on or any known source / template they have seen that might be helpful?

Thanks everyone!

Thomas

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If your loop is doing this:
    1. Pick a random number from 1 to 3
    2. Spawn an actor at the x,y position in row (random number) of the table
    1. Pick a random number from 1 to 3
    2. Spawn an actor at the x,y position in row (random number) of the table
    1. Pick a random number from 1 to 3
    2. Spawn an actor at the x,y position in row (random number) of the table

    Then you're going to have lots of overlap and gaps because the possible row values of choosing three random values between 1 and 3 include things like 1,1,1; 1,2,1; 3,3,2; etc.

    But I may be unclear on what's going on... are you wanting to spawn one of three actors in three positions per row for a certain number of rows?

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

  • hillsthillst Member, PRO Posts: 3

    Hi Tatiang, thanks for the speedy reply. I have pasted a link to the file below that I created. I see I can PM so sent you a copy of the GS file. If anyone else wants I can send to them to. Essentially you will see when preview is hit and you hit the replay button sometimes blocks fill the screen, sometime there are gaps and sometimes not much happens. My aim is to have the yellow, red, blue blocks fill the screen in no particular order, purely random. any help would be great.

    https://www.dropbox.com/sh/83lkf1335urby8h/AABrzLSTMp2G3yDmnpwECLxea?dl=0

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    This thread should be quite helpful. It's long but I'd focus on the contributions by @RThurman, especially his demo files and his explanation for how to choose random numbers without repeating.

    http://forums.gamesalad.com/discussion/76484/dont-spawn-more-than-once-in-one-spot/p1.

    One idea would be for each possible spawn location, choose a non-repeating random number between 1 and 3 and spawn the respective actor (e.g. 1=red, 2=yellow, 3=blue).

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

  • hillsthillst Member, PRO Posts: 3

    thanks tatiang, ill get cracking and try to work it out from there, thanks!

Sign In or Register to comment.