generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Decimal timer

Previous Thread :: Next Thread 
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Oct 2016 09:47 PM
How do you make a timer count down from 10 and prints the decimals?

e.g: 10, 9.9, 9.8, ect.


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Oct 2016 09:50 PM
for timer = 100, 0, -1 do
print(timer/10)
wait(0.1)
end
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 Oct 2016 09:54 PM
time = 10
while not time == 0 and wait(.1) do
time = time - 0.1
print(time)
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Oct 2016 09:54 PM
that'll actually never end :)
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 Oct 2016 10:06 PM
:o Why?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Oct 2016 10:09 PM
You keep subtracting by 0.1 (which can't be perfectly stored) so the error accumulates over time. Also the condition is wrong, NOT takes precedence over == but that's just another problem.

Through my test in 5.3, the closest to 0 I got from that loop was this:
1.8790524691781e-14
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 Oct 2016 10:20 PM
Why can't it perfectly store such a simple number as 0.1? Does that have to do with floats?
Also, what's wrong in the second line here? At this point it's not as coherent as your solution and doesn't fix the problem of accuracy, I'm just wondering how to use "not"

tock = 10
while not tock <.1 do
wait()
tock = tock - 0.1
print(tock)
end

23:18:46.896 - Workspace.Script:2: attempt to compare boolean with number
23:18:46.897 - Stack Begin
23:18:46.897 - Script 'Workspace.Script', Line 2
23:18:46.897 - Stack End
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 Oct 2016 10:22 PM
Could rounding the number after every operation prevent the inaccuracy, or is it possible that the inaccuracy is too large and it would round in the undesirable direction?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Oct 2016 10:23 PM
"Why can't it perfectly store such a simple number as 0.1? Does that have to do with floats?"
Yeah. Floats are essentially scientific notation in binary, you can't store 0.1 in binary (it repeats forever)

"Also, what's wrong in the second line here?"

The problem is
while not time == 0 do

is really the same as:
while (not time) == 0 do

Which will always evaluate to false because a boolean will never equal an integer
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Oct 2016 10:24 PM
"Could rounding the number after every operation prevent the inaccuracy, or is it possible that the inaccuracy is too large and it would round in the undesirable direction?"
It's actually just better to use integers and divide when needed (look at my solution) so you don't have to deal with floating point imprecision in the first place.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image