Bug when subtracting 0.1 from a real attribute

tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
edited December 2013 in Working with GS (Mac)
I just submitted this bug. It was also mentioned at http://forums.gamesalad.com/discussion/61950/counting-in-game-money but I hadn't realized it was as simple as I explain the post below this.

Using an every 0.1 timer or any other method, decrease the value of a real attribute by 0.1. When close to certain integers such as 1, the value of the real attribute changes from a tenth of a whole number to a long string of decimals.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    I just replaced the timer behavior with a Timers are for Chumps mod timer and it does the same thing.

    So then, check this out:

    Create a real attribute called game.counter and set the value to 10 (or any number... but the effects are greatest when you start at 10; not sure why).

    DisplayText game.counter
    When Touch is Pressed
         change attribute game.counter to game.counter-0.1

    Keep clicking until you get past 0. Same problem! Argh! Nothing to do with timers.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I reported this a while back. GS have said that it's been fixed and will be in the next build

    http://forums.gamesalad.com/discussion/comment/431809/#Comment_431809
  • pHghostpHghost London, UKMember Posts: 2,342
    edited December 2013
    Sounds related to my issue with counting in-game money that you were helping me with a few weeks back: http://forums.gamesalad.com/discussion/61950/counting-in-game-money

    The connection is the delta -- a 0.(0)1 fraction

    I got this reply from the customer support team:

    "The issue you are reporting is one that our Development team is aware of. Unfortunately, this is a demonstration of a limitation on how the engine (and display text) stores floating point calculations. The workaround you suggested: prec(game.coinCount, 2)+0.01 is definitely a valid way to keep your calculations limited to two decimal points.

    Apologies for any inconvenience caused."
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I've found the post and example file I reported with the decimal points problem for certain integers. This is the one that should hopefully be fixed in the next build

    http://forums.gamesalad.com/discussion/comment/430442/#Comment_430442
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    Thanks, @KevinCross. Sorry, I didn't realize it was scheduled for a fix. I thought the bug in that thread was limited to nightly builds, but since this is occurring with the regular 10.4.1 build I submitted it.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    And thanks also @pHghost. Very helpful information. I'm surprised this is an issue when it used to work fine (I've always created custom timers with 0.1 deductions). Ah well, patience is a virtue. :)

    Can you explain the prec(game.coinCount, 2)+0.01 expression? I used prec() but wasn't having much luck. Why are you adding 0.01?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • pHghostpHghost London, UKMember Posts: 2,342
    edited December 2013
    @tatiang

    prec() was a solution for my situation, but not sure if it would work universally.

    I was adding 0.01 for each coin collected, and it seems (as far as I understand it) that when you add fractions like this, it doesn't add that fraction precisely, there is some small discrepancy, which somehow manifests itself over time.

    prec() solved it because with every calculation, the prec() function is effectively flooring the number and so the discrepancy is reset and doesn't grow over time.

    For your situation, I'd hope something like this would work:

    every 0.1 seconds
    change: game.realNumber to: prec(game.realNumber, 1)+0.1

    If that doesn't solve the issue, then I guess the two problems might be unrelated.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I had tried change game.realNumber to prec(game.realNumber+0.1,1) and it wasn't working but it could have been another issue so I'll try both ways and see. Thanks.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Heard back from Support and they references this post which I hadn't seen before:

    http://forums.gamesalad.com/discussion/comment/387065/#Comment_387065

    Time for some workarounds!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.