- Joined
- Apr 20, 2020
- Messages
- 31
- Reaction score
- 14
- First Language
- Spanish
- Primarily Uses
- RMVXA
Hello,
I'm developing a game like Typeracer and I've been having some trouble when calculating CPM (Characters per Minute). Here's the code I made:
As soon as the player presses a key, a timer starts adding 1 to the time variable every frame.
The problem is that when "time" is lesser than 3600, when you convert it to minutes it will return a decimal value that gets rounded up to zero.
Eg: time = (1 minute / 3600 frames) = 2,77*10^-4 minutes
I tried using different time units, but the result is always inaccurate because I basically can't use any decimals. Is there any way to fix this?
Thank you.
I'm developing a game like Typeracer and I've been having some trouble when calculating CPM (Characters per Minute). Here's the code I made:
Ruby:
distance = $game_variables[2] # Define distance (all typed letters)
minutes = $game_variables[4] / 3600 # Define time (frames -> minutes)
cpm = distance / minutes # Speed equals distance divided by time
# Split CPM into separate integers
cpm1 = cpm / 1000
cpm2 = (cpm / 100) % 10
cpm3 = (cpm / 10) % 10
cpm4 = cpm % 10
# Show Numbers as Pictures
if cpm >= 1000
screen.pictures[17].show("Word - C_#{cpm1}", 0, 416 + 15*0, 551, 100, 100, 255, 0)
screen.pictures[18].show("Word - C_#{cpm2}", 0, 416 + 15*1, 551, 100, 100, 255, 0)
screen.pictures[19].show("Word - C_#{cpm3}", 0, 416 + 15*2, 551, 100, 100, 255, 0)
screen.pictures[20].show("Word - C_#{cpm4}", 0, 416 + 15*3, 551, 100, 100, 255, 0)
elsif cpm < 1000 && cpm >= 100
screen.pictures[17].show("Word - C_#{cpm2}", 0, 416 + 15*0, 551, 100, 100, 255, 0)
screen.pictures[18].show("Word - C_#{cpm3}", 0, 416 + 15*1, 551, 100, 100, 255, 0)
screen.pictures[19].show("Word - C_#{cpm4}", 0, 416 + 15*2, 551, 100, 100, 255, 0)
screen.pictures[20].erase
elsif cpm < 100 && cpm >= 10
screen.pictures[17].show("Word - C_#{cpm3}", 0, 416 + 15*0, 551, 100, 100, 255, 0)
screen.pictures[18].show("Word - C_#{cpm4}", 0, 416 + 15*1, 551, 100, 100, 255, 0)
screen.pictures[19].erase
screen.pictures[20].erase
elsif cpm < 10
screen.pictures[17].show("Word - C_#{cpm4}", 0, 416 + 15*0, 551, 100, 100, 255, 0)
screen.pictures[18].erase
screen.pictures[19].erase
end
As soon as the player presses a key, a timer starts adding 1 to the time variable every frame.
The problem is that when "time" is lesser than 3600, when you convert it to minutes it will return a decimal value that gets rounded up to zero.
Eg: time = (1 minute / 3600 frames) = 2,77*10^-4 minutes
I tried using different time units, but the result is always inaccurate because I basically can't use any decimals. Is there any way to fix this?
Thank you.
Last edited: