How do I make decimal point in a number always visible?

Get help using Construct 2

Post » Tue Feb 03, 2015 10:17 pm

So, I have a global varibale with initial value of 100, every 0.1 sec, 0.1 is subtracted from the varible (making it a 0.1 sec countdown timer) and sprite font is updated so that it shows correct "time". So it shows something like:
100
99.9
99.8
...
99.2
99.1
99
98.9

Id like it to show 99.0 too, how can I achieve it? I've tried to googleing it, also tried some *100, /100 variants, but with no avail. Any advice is apriciated!
Image
B
7
S
1
Posts: 70
Reputation: 843

Post » Tue Feb 03, 2015 10:20 pm

zeropad ;) https://www.scirra.com/manual/126/system-expressions

OR you could use len(text)

if yourTimeVariable = len(text) of 2 | setText to : yourTimeVariable & ".0"

Which checks the length of the time and if it's = 2 (meaning 90 only 2 characters not 90.1) then you set the text to your time variable and the ".0"
Image Image Image
B
60
S
19
G
6
Posts: 325
Reputation: 7,915

Post » Tue Feb 03, 2015 10:44 pm

Thanx, however, as far as I can tell, zeropad only ads digits ("0") in front of the number, and your other advice seems closer to what I'm looking for with need for some tweeking in case of single digit integers (or if I increase the variable to 1000) then in case of 3 digit integers.

There must be some simpler solution, something like "float(Variable,2)" where 2 defines the number of decimal places :)
Image
B
7
S
1
Posts: 70
Reputation: 843

Post » Tue Feb 03, 2015 10:57 pm

NP. Yeah I realized that on my first example..lol

I would recommend the second method with some events to handle extra or single integers. I had to do something similar for my game timer.

I assume you could use float in a text expression... but from my understanding C2 uses expression float(x) so I don't know if you could set decimal place so to speak. Would have to test to be certain.
Image Image Image
B
60
S
19
G
6
Posts: 325
Reputation: 7,915


Return to How do I....?

Who is online

Users browsing this forum: MSNbot Media, SEBASTIANSSS and 2 guests