Spawn random actors without repeat

jerlant360jerlant360 Member Posts: 82
edited December 2012 in Working with GS (Mac)
Hi guys , i have a spawner who spawn 3 falling actor at certain time , the issue is that the 3 actors spawned are always the same one , how can i make it spawn without repeat an actor?

Thanks

Comments

  • hotMagichotMagic Member, PRO Posts: 266
    To start, make a variable in the spawner and choose a random number 1-3 to assign to it at the moment you are going to spawn.

    Have the rules say, if 1, spawn here, if 2, spawn here, and so on.

    This will keep it sort of random.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    If you want random without repeat, create a table of possible actors. For example, you might represent each actor as an integer, 1-10, with each number in a separate row.

    Then, in your spawner actor do this:
    When [condition or timer]
         Change Attribute self.Random (type: index) to random(1,TableRowCount(TableName))
    When self.Random=1
    [spawn actor 1]
    When self.Random=2
    [spawn actor 2]
    etc.
    Delete Table Row at index self.Random

    If you then repeat this entire rule via a condition or a timer or a loop, it will choose a random row of the table to pull a number from and then delete that row from the table so that it isn't re-used.

    Keep in mind that you'd want to stop spawning actors when the TableRowCount reaches zero.

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

  • jerlant360jerlant360 Member Posts: 82
    Thanks a lot guys!!
Sign In or Register to comment.