Float value to integer?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Lutka
Newbie
Posts: 23
Joined: Mon Apr 24, 2017 11:13 am
Contact:

Float value to integer?

#1 Post by Lutka »

This is better to explain by just showing you

Here's my code

Code: Select all

vbox:

                label _("Text Speed \n")

                bar value Preference("text speed")

                hbox:

                    text _("{color=#ff88ba}Character Per Second: {/color}")
                    text "{color=#ff88ba}[preferences.text_cps]{/color}"
That's in the preferences menu. I like how it shows the text speed in real time as you move the bar. My only problem is that it shows it as a float value meaning the number has way too many decimals. Preferrably, I'd not have it show any decimals whatsoever.

I tried defining a new value and then using that in the preferences menu like "txtspd = int(preferences.text_cps)"

But then, when I used this in the preferences menu, the number didn't update in real time. Or at all, for that matter. It just stayed in the number that it was set to when the game loaded (as is to be expected I suppose)


Any ideas?
Thanks

Lutka
Newbie
Posts: 23
Joined: Mon Apr 24, 2017 11:13 am
Contact:

Re: Float value to integer?

#2 Post by Lutka »

Okay sorry, I got it. If anyone is interested in the solution

Code: Select all

text "{color=#ff88ba}Character Per Second: {/color}"
                    $ val = int(round(preferences.text_cps))
                    $ val = '∞' if val == 0 else val
                    text "{color=#ff88ba}[val]{/color}"

Post Reply

Who is online

Users browsing this forum: Bing [Bot]