Question about randomising position

Hi there. I have a small problem im struggling with.

I have 5 instances of the same actor in a scene (Its a block). I want to make their Y position random with a min and a max. BUT i want to make a random instance of that actor with a different limit (min,max) to their random position. Basically, how can i make them all random within a limit (min, max) but make any one of those be randomly chosen to have a different min and max position?

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2014

    Hi @breuban This problem is more complex than it seems...

    The way I'd tackle it is, divide up the area where the 5 actors are to randomly move to, into a grid of squares, each square the same size as the 5 actors. (I mean invisible squares, to indicate areas, unless you want them to show).

    Make an integer attribute, called ActorPos, and another called RandPick.

    Then make a table, with as many rows as there are squares, each row having two (integer) columns. Fill these two columns of each row with your x and y positions of the middle of each grid square.

    Make another empty table.
    For the following example, I'm going to assume there are 25 grid positions (in a grid of 5 x 5).

    In your Rules, in an actor off of the screen area - (I'll assume the process is triggered by a boolean, which you would set to true in a button or wherever)

    When GoRandPos is true
    Copy Table Table1 to Table2
    

    Now in each of your instance actors, put the following:

    ---this one in your 1st actor

        When GoRandPos is true
    Timer: After .1 seconds --only need this delay in first actor's Rules
        When ActorPos = 0 
        Change Attribute RandPick to random(1,25)
        Change Attribute self.Position.X to tableCellValue(table2,RandPick,1)
        Change Attribute self.Position.Y to tableCellValue(table2,RandPick,2)
        Add/Remove Row Table2 Action: Remove Row At Index RandPick
        Change ActorPos to ActorPos + 1
    

    ---this one in your 2nd actor

    When GoRandPos is true
    When ActorPos = 1 
    Change Attribute RandPick to random(1,24)
    Change Attribute self.Position.X to tableCellValue(table2,RandPick,1)
    Change Attribute self.Position.Y to tableCellValue(table2,RandPick,2)
    Add/Remove Row Table2 Action: Remove Row At Index RandPick
    Change ActorPos to ActorPos + 1
    

    etc, for the other 3 actors. (Note that ActorPos is increasing by 1 each time, and the random max.number of RandPick is decreasing by 1 each time).


    At the end of the rules in the fifth actor, put
    Change GoRandPos to false
    and instead of putting Change ActorPos to ActorPos + 1, put
    Change ActorPos to 0
    (and copy Table 1 to 2 again if you want, to be totally reset).

    I told you it was more complex than it seems... :wink:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • breubanbreuban Member Posts: 13

    Woah :o Thanks for takin the time to write that out for me Gyroscope, much appreciated. I haven't tackled tables yet so i guess i have a lot of reading to do! Once i understand how it all works, ill implement your suggestion and post an update! Thanks again :)

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2014

    You're welcome, @breuban :smile: Some GS problems intrigue me and I enjoy trying to find a solution for them.

    Don't worry about Tables, once "the penny drops" about them you'll find them easy to handle.

    I reckon your first step to learning about them would be from the Cookbook:

    http://cookbook.gamesalad.com/tutorials/2/parts/25

    I think there must be info about Tables in the Manual too, surely... http://gamesalad.com/manuals

    And if you Google: tables tutorial GameSalad , a lot of stuff comes up, including some excellent video tutorials. All the best, it'll all fall into place!

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.