Distribute values for actors

ludoFludoF Member, BASIC Posts: 5

Hi guys,

I have been struggling for hours on something which seems pretty straight forward.

I have 4 different actors and I want them to display 4 numbers (1,2,3,4 and never the same) . I have created a table with 4 rows and 1 column to store those values.

I have a rule which set the attribute (which store the numbers) with this expression:

tableCellValue( game.SelectorTable ,random(1,tableRowCount( game.SelectorTable )),1)

After each "change attribute" (one per actors) I remove the row which was storing the value. As my attribute has one of the value 1,2,3,4 I just use the value of the attribute to delete the corresponding row if that makes sense... (row 1 has the value 1, row 2 as value 2, and so on)

So it's working except that sometimes I will have my actors with the values 1,1,2,4 or 1,3,4,3... I think there is just 2 identical numbers when it happens, I have never seen more.

Any ideas of what I am doing wrong?
If it's not clear, basically I am trying to distribute the value 1,2,3,4 to four actors as a card dealer would distribute 4 cards to 4 players.

Thanks!

Comments

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

    Most likely you are choosing a random value from within all four actors instead of using a single "control" actor to choose all four values.

    Do this from a single actor:

    Change attribute self.randomRow to random(1,tableRowCount(game.SelectorTable))
    Change attribute game.Value1 to tableCellValue(game.SelectorTable,self.randomRow,1)
    Delete Table Row at index self.randomRow

    Then repeat this within that same actor for the other three values:

    Change attribute self.randomRow to random(1,tableRowCount(game.SelectorTable))
    Change attribute game.Value2 to tableCellValue(game.SelectorTable,self.randomRow,1)
    Delete Table Row at index self.randomRow

    Change attribute self.randomRow to random(1,tableRowCount(game.SelectorTable))
    Change attribute game.Value3 to tableCellValue(game.SelectorTable,self.randomRow,1)
    Delete Table Row at index self.randomRow

    Change attribute self.randomRow to random(1,tableRowCount(game.SelectorTable))
    Change attribute game.Value4 to tableCellValue(game.SelectorTable,self.randomRow,1)
    Delete Table Row at index self.randomRow

    Assign each of the four card actors to each of the game.Value# attributes that were generated above.
     
     
    You can also do this with a single spawner actor:

    Create a "card" actor with an integer attribute called value. Create a "dealer" actor with integer attributes called self.index and self.randomRow. Create a game attribute called game.passValue.

    Create these rules in the "dealer" actor:

    Loop self.index over the value 1 to 4
        Change attribute self.randomRow to random(1,tableRowCount(game.SelectorTable))
        Change attribute game.passValue to tableCellValue(game.SelectorTable,self.randomRow,1)
        Spawn actor "card"
        Delete Table Row at index self.randomRow
        

    Create this in the "card" actor

    Change attribute self.value to game.passValue
    DisplayText self.value

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

  • ludoFludoF Member, BASIC Posts: 5

    Thanks Tatiang!

    I'll take a look as soon as possible and I'll let you know how it went!
    Thanks

Sign In or Register to comment.