playMaker

Author Topic: Rounding to the nearest array member  (Read 1535 times)

Emil

  • Playmaker Newbie
  • *
  • Posts: 3
Rounding to the nearest array member
« 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!

Deek

  • Full Member
  • ***
  • Posts: 133
Re: Rounding to the nearest array member
« Reply #1 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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rounding to the nearest array member
« Reply #2 on: August 11, 2017, 11:55:57 AM »
Hi,
There is a arraymaker tutorials listed on the user tutorial wiki page

Emil

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Rounding to the nearest array member
« Reply #3 on: August 15, 2017, 03:38:08 PM »
Fantastic, thank you both!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Rounding to the nearest array member
« Reply #4 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