I'm setting up a HUD, and I want it to display the ratio of two variables:
text "Ratio: [x]"
works fine to display the value of var1. However, if I try to display the ratio of x to y:
text "Ratio: [x / (x + y)]"
it treats the equation like a name and throws an exception.
I don't need the screen to change the game state, just to display the statement's output. Can I do this, or do I need to create another variable for the ratio that is updated whenever x or y is changed? Or is there some simpler way to make this work?
Math on a screen [Solved]
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.
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.
-
- Regular
- Posts: 33
- Joined: Thu Oct 19, 2017 8:04 pm
- Contact:
Math on a screen [Solved]
Last edited by DoubleProlix on Sat Jun 23, 2018 7:39 pm, edited 1 time in total.
Re: Math on a screen
The square bracets in text is used to show value of a variable not to calculate it. Try
Code: Select all
screen scr_name():
$ res = x / (x + y)
text "Ratio: [res]"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Math on a screen
Code: Select all
screen a:
$ x,y = 7.0, 12.0
text "Ratio: {:.03f}".format( x / (x + y) )
Remember to cast x and y to floats rather than integers to avoid python pre 3 rounding the result
Last edited by Remix on Sat Jun 23, 2018 7:39 pm, edited 1 time in total.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
-
- Regular
- Posts: 33
- Joined: Thu Oct 19, 2017 8:04 pm
- Contact:
Who is online
Users browsing this forum: No registered users