User Tag List

Results 1 to 10 of 10

Thread: Force float value (decimals)

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Force float value (decimals)

    OK here's a problem I'm having (I would put it in the MMF2 general section but nobody seems to reply in there, I'm much more fond of you guys in here )

    I've created a perfectly working control customisation system which I'm willing to share as an example with people if you can help me sort this one feature out.

    See, I have a controls frame in which the user can drag the virtual controls around the screen to the position they desire, and it saves their positions in INI items so that they stay in the user's chosen position for future playthroughs. I've also set up 'bigger' and 'smaller' buttons which allow the user to scale the buttons up or down, and to store the scale value inside the INI also. The only problem is that scale always uses a float value, with 1.0 being normal scale, 2.0 being double, 0.5 being half. On PC this works, I can store a float value (decimal) in the global values and inside of the INI, but on iOS it forces it to an integer, so once the player leaves the frame it's 'snapped' to the nearest full value. I've tried storing the scale value *100, then setting the scale to the stored value /100, but the expression still results in an integer.

    Since the iOS runtime doesn't seem to want to store float values in global values (and potentially not in INIs either, not sure if it's the INI or the global value or both causing the problem), I am sure I need to use the scale*100 => value/100 method, so how do I ensure that an expression returns a float (decimal) value and not an integer (whole number)?

  2. #2
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Francois's Avatar
    Join Date
    Jul 2006
    Location
    Montpellier, France
    Posts
    6,920
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I just checked the code to be sure. Global value accept floating point numbers. Are you sure they are not converted to int in your calculations later?

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, it works on the PC but not on the iPhone. Perhaps the INI doesn't store float values on iOS?

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    OK here's the problem with getting around it...

    This expression, for example:

    320/100

    Will always return 3.

    I need to get it to return 3.2.

    I've tried using:

    0.0+(320/100)

    But that still returns 3.

    I want to get around the issue by storing the scale as a percentage (scale*100) and then dividing it by 100 to get it precise.

    Starting to think using *0.01 instead of /100 might be the solution...

  5. #5
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,057
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Try (320/100)*1.0

  6. #6
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Got it. 320*0.01 did the trick.

  7. #7
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Århus
    Posts
    3,456
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    MMF2 does the calculations in parenthesis first. If you have a parenthesis that only contains integer math then it will only do integer division and give that result to the rest of the expression.
    This would work too: 320/100.0

  8. #8
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleMac Export ModuleSWF Export Module
    AndyH's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,445
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I tend to use the method Andos has posted above - for any multiplications or divisions with constant values. I also use either 0.0+ or *1.0 within the order of precedence when problems arise.

    Francois/Andos - does INI allow floating point values to be stored? DistantJ, you could possibly convert the number to a string to store in the INI as another alternative?
    Andy H @ ovine.net
    Awful Jokes - a new cartoon every day: http://awful.ovine.net/
    Ovine's games: http://www.ovine.net

  9. #9
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Århus
    Posts
    3,456
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    I remember that the INI object didn't support it on PC at least. I don't know if it does now.
    Anyways, it doesn't look like iOS supports writing floating point numbers right now, but there is always the workaround (as AndyH pointed out) of converting them to strings first and then store them that way (as strings).
    The performance should be the same. I will check if the PC version works the same way, otherwise we will change it.

  10. #10
    Clicker Fusion 2.5Fusion 2.5+ DLC

    Join Date
    Sep 2010
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having a similar problem.

    I am using INI++ on my PC along with Common Dialogue Object. It saves a decimal just fine, but when I try to load the decimal back into a global value it only returns an integer.

    I tried sending the value to a string...
    I tried x/100
    I tried 0.0+x/100
    I tried x*0.01
    I tried running a debug window and watching the values change at runtime and it always returns an integer, even with floating decimals of up to 4 places and they all return an integer. All I can do is successfully store a decimal inside an .ini file, but can only retrieve its whole number.

    The problem seems to occur when I load an INI file using the common dialogue object's open dialogue box

Similar Threads

  1. Velocity value as Float?
    By danjo in forum Fusion 2.5
    Replies: 2
    Last Post: 26th October 2013, 08:15 AM
  2. float on water
    By foyzul2002 in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 22nd April 2013, 04:50 PM
  3. [BUG / Problem ]Float-value
    By Pharanygitis in forum SWF/Flash Export Module Version 2.0
    Replies: 5
    Last Post: 17th September 2011, 08:46 PM
  4. Return a Float
    By Jaffob in forum Extension Development
    Replies: 3
    Last Post: 3rd April 2009, 11:05 PM
  5. Global Value Float Bug
    By xerus in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 31st January 2008, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •