playMaker

Author Topic: Float Round To Nearest  (Read 2778 times)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Float Round To Nearest
« on: January 26, 2015, 07:35:26 AM »
Rounds a Float variable to the nearest specified multiplier.

Also on Ecosystem.
« Last Edit: February 17, 2015, 11:04:33 AM by Lane »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #1 on: January 26, 2015, 11:21:22 AM »
With each action you guys keep making playmaker better and better.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #2 on: January 27, 2015, 11:08:20 AM »
I just used this on a slider.  So anyone making a slider can use this.

So I have a pause menu pop up.  The player can use the mouse to select the slider.  Sense it is a float, it can be any float value.  I just display a percent to make it easier to read forgetting the rest even though technically they are there.  So .054567 would display as '55%'.

However, it doesn't seem to do what I thought it would.  It seems to be going in increments of 15.  So 43 becomes 60.  Now I do add or subtract 5% as well.  So 43 plus 5 = 48.  The round should move it to 50 but it goes up to 60.

So I click with mouse at 43. 
Then I use the joystick right axis (FSM2 un-shown) to trigger 'increment right'. 
'Add'  is where I add 5.  I use the round here to 0.05.
'Set slider value' state is where I clamp it to 0 an 1.
"Set Slider onscreen" sets the property of the slider
"Show Slider Number" displays it, plays sound and such.  More used for mouse.
Any ideas of how I am setting this wrong?

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #3 on: January 27, 2015, 11:14:02 AM »
Here are screenshots of pause menu. 

The top left has 'pause menu slider' at 0.4293623 which displays at 43%.
I click right to add 5% and it goes to 0.6 or 60%.


Now I did reverse the position of the round and float add in that state which sort of fixed the problem.  However, there is some bug (on my end or yours) that sometimes it will do 5% and sometimes will do 15%.  I get it to 0% and then it then only goes up or down in 15% increments.  the code here is really simple so that's weird.
« Last Edit: January 27, 2015, 11:35:12 AM by wheretheidivides »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: Float Round To Nearest
« Reply #4 on: January 27, 2015, 11:35:21 AM »
Maybe it's running it more than once because of your inputs, looks like a weird way to handle a slider.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #5 on: January 27, 2015, 01:17:52 PM »
Maybe it has something to do with the joystick/button adding 5% (and rounding), then the playmaker proxy doing a 'on value changed'.  maybe the proxy sees a change and thus changed the float value.

If true, is there a way around this?

UPDATE:  When it messes up (mouse click on slider then use keyboard/joystick) and does it wrong at 15% increments (add or subtract),

then I click on another window like the scene and
then click back on the game window, it fixes it. 
It will now go up or down at 5% increments (not 15%)  Weird.
« Last Edit: January 27, 2015, 02:24:02 PM by wheretheidivides »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #6 on: January 29, 2015, 10:09:06 PM »
I keep getting this console error on this action. 

Assets/PlayMaker Custom Actions/DownloadedFromForems/FloatRoundToNearest.cs(53,41): warning CS0472: The result of comparing value type `HutongGames.PlayMaker.FsmInt.Value' with null is `true'

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #7 on: February 07, 2015, 07:34:47 PM »
So how do I get rid of this error so it won't keep popping on in the console?

"Assets/PlayMaker Custom Actions/DownloadedFromForems/FloatRoundToNearest.cs(53,41): warning CS0472: The result of comparing value type `HutongGames.PlayMaker.FsmInt.Value' with null is `true'"

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Float Round To Nearest
« Reply #8 on: February 16, 2015, 11:34:14 PM »
Hi,

 you can insert a pragma declaration and the related warning will not be raised:

http://answers.unity3d.com/questions/21796/disable-warning-messages.html

when I'll move that action to the ecosystem, I'll clean up that warning.

 Bye,

 Jean

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #9 on: February 17, 2015, 10:49:06 AM »
I don't know C#.  So I just add:

"#pragma warning disable 0472"

at the top of the action script somewhere?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: Float Round To Nearest
« Reply #10 on: February 17, 2015, 11:05:38 AM »
I don't see the warning in 5f1, but I fixed the line. The warning should go away.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 479
    • View Profile
Re: Float Round To Nearest
« Reply #11 on: February 17, 2015, 11:12:09 AM »
Could you post it here so I can download/?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: Float Round To Nearest
« Reply #12 on: February 17, 2015, 11:33:37 AM »
Its in the first post and ecosystem.