Time accuracy problem
Hello!
I have a reaction timer that constrains game.Score to game.Time-game.startTime. When the start button is clicked, I change game.startTime to game.Time. When the stop button is clicked, I have a rule that checks to see if game.Score equals 2. If so, I reward the player. What is happening is that when game.Score is 1.91 or 2.05 or anything close to 2, that rule triggers. Is there a reason that the rule condition is true even though 1.91≠2? I am not rounding anything and I am using real attributes instead of integers.
Best Answers
-
Armelline Posts: 5,369
Hey. Very interesting problem! I've not encountered this issue before but I can certainly reproduce it. It seems to be a fundamental issue with GameSalad (@CodeWizard, @artent42?), but you can work around it to at least some extent.
When you do your comparison, force GameSalad to use decimal places. Right now it seems to be at least partially ignoring them, but you can force it to be much more precise - though possibly not exactly precise.
Use the precision(number,decimals) function to force as many decimals as possible to be counted. I'd suspect something like 10 would be enough, and that worked for me.
So you'd end up with this:
When numeric expression precision(EndTime,10)-precision(StartTime,10) = 2 Add to score
If someone can click at 2 seconds to 10 decimal places, then I'd give them the points, personally. Closest I could get was 2 decimal places.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
-
RThurman Posts: 2,880
@pw -- In addition to the way @Armelline explained, you can also use a boolean comparison. It would look something like this:
-
RThurman Posts: 2,880
@Armelline -- Your suggestion is likely the way to go. But please keep in mind that there is no single timer display. Instead, there are four separate digits (actors) on display. And each actor is is using 'game.score' - rather then 'game.endscore' (which is actually used in the test). And each display actor is getting its own version of 'game.score' according to its layering.
This is really a design issue. And the design issue is creating a logic issue. Once @pw gets a little more experience with GameSalad (and with how to resolve logic issues) I am sure s/he will be a better developer.
I think we both agree that the logic needs some tweaking. For @pw (and for me) this is a great learning opportunity.
In the end, it always boils down to logic.
Answers
Gonna try to reach out for a final attempt of solving this issue. @Armelline has helped me out alot and managed to narrow the accuracy down from the reward firing at anywhere between 1.90-2.10 seconds to now only firing between 1.97-2.00 seconds. It does seem a bit buggy at 2.00 though, as the text (example reward) only flashes quickly while at 1.97-1.99 staying on screen until the stopbutton is released. I've added a display text to check the game.Score versus what the timer itself is showing and it always differs 0.02-0.04 (mostly 0.03) seconds (This is the core problem I believe), but I don't know how to solve it, or if it might be an issue on GameSalads front.
I'm gonna add a dropbox link for anyone interested in having a look. (It's a stopwatch with a start and a stop button)
https://www.dropbox.com/sh/9hkq3a01dontayu/AADJ9kmtCSkBkYR45Br1cAzba
Try this version. Its working as far as I can tell. (Its impossible for me to hit the stop button exactly at 2.00. I suspect you will need to relax that a bit.)
Will do as soon as I get home!
Hey @RThurman. We tried this method, but unfortunately it doesn't work. The timer will still trigger within a ~10 centisecond range.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@Armelline
Actually it only triggers at 1.99 and 2.00 when you set the endscore to prec(game.Score,2)
@RThurman, also wrote that: "Ok a quick trial of the following expression in the 'hundredths' display seems to give consistent results:
round((prec( game.Score ,2)% self.Div )/( self.Div /10))..".png"
I even got another 2.00 by accident. And it still works."
I didn't manage to hit either of those times but had it trigger for me at 2.01.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Interesting, I've actually never had it trigger on 2.01 (and I hit it 15 times or even more), just on 1.99 and 2.00
You must be talking about the display showing those numbers.
The actual timer is accurate down to six decimal places. But the display is not. The way the display is set up it has two problems. First, It is subject to rounding error. And second its layering allows a slightly different time to be shown.
Remember, the way its currently set up the timer is using 'game.endtime' to test clickspeed. But the display is using 'game.score'. And 'game.score' keeps running for a very short duration after the stop button is pressed.
Perhaps we're all approaching this from the wrong direction. There are two problems - GameSalad doesn't always accurately judge is a number = 2, and the timer display doesn't accurately reflect the timer itself (game.Score).
So rather than trying to find out if game.Score = 2, perhaps the best way to go about it is to check if the timer is currently displaying 2.00 rather than if the timer actually is at 2.00.
I don't have time to test it now but if you're comparing to the timer display, even if it's slightly out of sync it doesn't matter.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support