Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Emil on August 10, 2017, 01:45:17 PM

Title: Rounding to the nearest array member
Post by: Emil on August 10, 2017, 01:45:17 PM
I'm trying to use PM for rounding a float to the nearest array member.
Lets say array has 4 members:
5.0
17.0
35.0
50.0

If input is 11.5 it should return 17.0, if input is 41.2 it should return 35 etc.

Any tips highly appreciated!
Title: Re: Rounding to the nearest array member
Post by: Deek on August 11, 2017, 11:51:35 AM
There is no such action for normal arrays, so you would have to do the math manually, but there is an action for Array Lists called "Array List Get Nearest Float" which does exactly what you ask for. So I think it's your best bet to download the Add-on ArrayMaker either from the Ecosystem or from here: https://hutonggames.fogbugz.com/?W715
and learn to use ArrayLists & HashTables (it isn't that hard to understand and they have a lot of potential that can be very useful for you in the future).

After downloading and installing, you pretty much just have to add the component "Play Maker Array List Proxy" to one of your GameObjects, prefill it with the same floats as your array and reference/drag that GameObject in the Array List actions (you can leave the "Reference" field empty on both the actions and the component, it's only useful if you use several ArrayLists on one GameObject).

Using ArrayMaker for this is probably the easiest route you can take to achieve your desired behaviour.
Title: Re: Rounding to the nearest array member
Post by: djaydino on August 11, 2017, 11:55:57 AM
Hi,
There is a arraymaker tutorials listed on the user tutorial wiki page (https://hutonggames.fogbugz.com/default.asp?W548)
Title: Re: Rounding to the nearest array member
Post by: Emil on August 15, 2017, 03:38:08 PM
Fantastic, thank you both!
Title: Re: Rounding to the nearest array member
Post by: jeanfabre on September 18, 2017, 04:03:56 AM
Hi,

 also, with ArrayList, you have an action called ArrayListGetNearestFloatValue which will do that.

I also just created an equivalent for built in arrays, on the Ecosystem, the action is called ArrayGetNearestValue and it works with floats and ints arrays.

 Let me know how it goes.

Bye,

 Jean