playMaker

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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Float Round To Nearest
« on: January 26, 2015, 09:35:26 AM »
Rounds a Float variable to the nearest specified multiplier.

Also on Ecosystem.
« Last Edit: February 17, 2015, 01:04:33 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wheretheidivides

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

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Float Round To Nearest
« Reply #2 on: January 27, 2015, 01:08:20 PM »
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: 496
Re: Float Round To Nearest
« Reply #3 on: January 27, 2015, 01:14:02 PM »
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, 01:35:12 PM by wheretheidivides »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Float Round To Nearest
« Reply #4 on: January 27, 2015, 01:35:21 PM »
Maybe it's running it more than once because of your inputs, looks like a weird way to handle a slider.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Float Round To Nearest
« Reply #5 on: January 27, 2015, 03: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, 04:24:02 PM by wheretheidivides »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Float Round To Nearest
« Reply #6 on: January 30, 2015, 12:09:06 AM »
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: 496
Re: Float Round To Nearest
« Reply #7 on: February 07, 2015, 09: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: 15500
  • Official Playmaker Support
Re: Float Round To Nearest
« Reply #8 on: February 17, 2015, 01:34:14 AM »
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: 496
Re: Float Round To Nearest
« Reply #9 on: February 17, 2015, 12:49:06 PM »
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: 2511
  • Mender of the past
    • Cleverous
Re: Float Round To Nearest
« Reply #10 on: February 17, 2015, 01:05:38 PM »
I don't see the warning in 5f1, but I fixed the line. The warning should go away.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wheretheidivides

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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Float Round To Nearest
« Reply #12 on: February 17, 2015, 01:33:37 PM »
Its in the first post and ecosystem.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D