Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on May 17, 2012, 10:24:28 AM

Title: get unique Random int from int pool
Post by: jeanfabre on May 17, 2012, 10:24:28 AM
Hi,

 Ok, this one might seem odd at first but it has infact a lot of use cases.

 So image a deck of card ( the current hot topic on this forum): you want to pick 5 of them to give the player a hand. You need a system that must not pick the same card again, this is an obvious statement but difficult to put into an algorithm if you are not used to scripting technics.

Based on that example, I made a simple action, that let you pick them cards.

let's say 10: we will have 1 2 3 4 5 6 8 9 10 to pick from, and we want to pick 5 of them

so this action will first pick let's say 3, the pool is now 1 2 4 5 6 7 8 9 10,
next pick, let's say 5, the pool is now 1 2 4 6 7 8 9 10
And so on

 so if we actually pick all of them ( pool count being equal to the serie count), we end up with a simple shuffle system.


 It works with ints, so you define first the range or pool to pick ints from. Why ints?, because they are easy to work with and most of the time represent a reference you work with.

 It's also something you can and should use with ArrayMaker, so that you can pick unique items from an array and be sure you don't get twice the same in the process, and you can use a ArrayListGet action and simply pass that int you got from this system.


If anyone has problems grasping this, let me know, and I'll do a working sample.

The action name is GetNextRandomInt (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Math/GetNextRandomInt.cs)
you can get this action on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181), or preview its code source on Github (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Math/GetNextRandomInt.cs)



Bye,

 Jean
Title: Re: get unique Random int from int pool
Post by: Robbi on December 03, 2012, 08:38:52 AM
Hi Jean,

I am indeed in need of this script, but I am a noob programmer.

Therefore, would need more of your thorough guide on how to install and use this script in a step by step instruction?

thanks a million, and sorry for the trouble...
Title: Re: get unique Random int from int pool
Post by: Alex Chouls on December 03, 2012, 11:01:42 AM
Hi Robbi,

I haven't used this action, but to install any action you just need to save it as a script in your project. E.g., create a file called GetNextRandomInt.cs anywhere in your assets folder and copy/paste the code into it.

This line in the code tells you where to find the action in the Action Browser:
[ActionCategory(ActionCategory.GameObject)]

You can then use this like any other action...
Title: Re: get unique Random int from int pool
Post by: Robbi on December 03, 2012, 03:59:02 PM
Hi Alex,

thanks for the guide.

 :D
Title: Re: get unique Random int from int pool
Post by: then00b on February 05, 2013, 11:41:36 AM
This is beautiful. Thanks for this, Jean!
Title: Re: get unique Random int from int pool
Post by: djaydino on August 15, 2015, 07:44:15 AM
Hi,
i have added this action to the ecosystem as it was not there yet.
And i added a reset option
Title: Re: get unique Random int from int pool
Post by: jeanfabre on August 15, 2015, 05:12:28 PM
Hi,

 Excellent, that's the spirit!!! Thanks :)

 Bye,

 Jean