Get Highest Value?

MoikMoik Member, PRO Posts: 257
edited May 2014 in Working with GS (PC)

I'm trying to have my game use the highest value among a set of random results. I can't find anything about sorting or comparing values.

Say I have game.Roll1 with a value of 8, game.Roll2 with a value of 16, and game.Roll3 with a value of 11. How can I get the game to realize that game.Roll2 is the highest, and add it to an existing table integer?

An example implementation: http://invisiblecastle.com/stats/roll/
See the option for 4d6.takeHighest(3).

Ideally I would want a function where you can dynamically set the number of rolls, the random range, and how many of the highest or lowest are selected as they do there.

Comments

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

    You could do something like this, though it's not automated.

    https://www.dropbox.com/s/8svdxb5rvi1jkzy/Highest Roll.zip

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

  • TosanuTosanu Member, PRO Posts: 388
    edited May 2014

    If youre just comparing three dice rolls, id do it like this.

    If Roll1 > Roll2

    {If roll1> roll3
    {RollConfirmed = roll1
         {Else Rollconfirmed = roll3
    

    ELSE
    If roll2 > roll3
    (Rollconfirmed = roll2

         {Else Rollconfirmed = roll3
    

    And then you can use rollconfirmd to add to the table integer, or perhaps simply put a change table value in place of rollconfirmed= functions.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Have not looked at the others demos, but it's pretty simple with the Max() function.

    Simply set it up like this

    Change attribute game.HighestValue to max(game.Roll1, game.Roll2, game.Roll3)

    This will pick the attribute with the largest value and assign it to the game.HighestValue attribute, which is just an integer attribute you'd create to hold that largest value.

  • TosanuTosanu Member, PRO Posts: 388

    Wow my suggestion was overcomplicated. I'd say go with Brayden's.

  • MoikMoik Member, PRO Posts: 257
    edited May 2014

    Interesting! Thanks! I'll try those out.
    I had hacked together a sort of... I used a High Score system within a loop. It was just rolling one die as many times as I needed and then I used whatever the High Score was.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Here's a demo of the method listed above. Just FYI, the Max() function (found in the RoundRules actor) can contain more than 3 attributes if needed.

Sign In or Register to comment.