Get Highest Value?
Moik
Member, PRO Posts: 257
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
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
If youre just comparing three dice rolls, id do it like this.
If Roll1 > Roll2
ELSE
If roll2 > roll3
(Rollconfirmed = roll2
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.
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.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Wow my suggestion was overcomplicated. I'd say go with Brayden's.
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.
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.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx