Decimal WebStorage High-Score

Get help using Construct 2

Post » Thu Feb 20, 2014 1:35 pm

Hey Guys,

I finally managed to make my game keep the highscore. Alas, now I am facing a different problem. The point of the game is to survive as long as you can. Because of this, the score is measured by time being alive. So your score is your time. The problem arises when the player's time is 4.8 secs and the HighScore only captures 4. In a fast paced game like mine, these 0.8 seconds can mean a lot and I would like to know a way to make the highscore show the decimal aside from the round number.

Any ideas will do :)

thanks!
B
9
S
1
Posts: 51
Reputation: 639

Post » Thu Feb 20, 2014 1:45 pm

Multiply by 10 -> SAVE -> LOAD -> divide by 10 -> display.
B
7
S
2
Posts: 93
Reputation: 797

Post » Thu Feb 20, 2014 1:56 pm

I know this will sound like a silly question but, have you tried NOT rounding the number? :P You're probably using int() to convert from text or something.

If you want a specific number of decimal places rather than all of them (which is a lot) the formula is round(Num*N)/N, where N is 1 followed by a number of zeroes equal to the numberof decimal places you want to keep (1 for no decimal places, 10 for 1 decimal place, 100 for 2 decimal places, etc)
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Feb 20, 2014 2:06 pm

Hey!

So this is what it says at the moment
int(WebStorage.LocalValue("HighScore"))

I tried putting *1)/100 but it underlined the * saying that it's not working. I also tried using round instead of int but no luck there either
B
9
S
1
Posts: 51
Reputation: 639

Post » Thu Feb 20, 2014 2:12 pm

Read my reply again. When you use int() it will truncate to an integer and integers don't have decimals. What you want is a float

Use float() instead, so round(float(value)*10)/10 will give you one decimal place, replace the two 10s with 100s for 2 decimal places, etc
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Feb 20, 2014 2:16 pm

Tried it out but it created somewhat of chaos. It's showing really low numbers now, 0.03 and 0.04 respectively. It seems like it is actually dividing the results with 100.

Suggestions?
B
9
S
1
Posts: 51
Reputation: 639

Post » Thu Feb 20, 2014 2:17 pm

Post what you have, probably a typo somewhere
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Feb 20, 2014 2:18 pm

Sorry! Got it working, i placed 1/100 instead of 100/100

Thank you so much!

You rock man! :)
B
9
S
1
Posts: 51
Reputation: 639


Return to How do I....?

Who is online

Users browsing this forum: SputnikCZ, UberLou and 2 guests