Bug when subtracting 0.1 from a real attribute
tatiang
Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
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.
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
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
http://forums.gamesalad.com/discussion/comment/431809/#Comment_431809
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."
http://forums.gamesalad.com/discussion/comment/430442/#Comment_430442
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
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.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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