[Solved!] Converting a number to percentage

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
Mikasa01
Newbie
Posts: 13
Joined: Sat Jul 11, 2020 1:01 pm
Contact:

[Solved!] Converting a number to percentage

#1 Post by Mikasa01 »

Hello. Is there an easy way to convert a big number to percentages?

Something like this:

Code: Select all

    $ enemy_max_hp = 4246
    $ enemy_hp = enemy_max_hp
    
label start:
     "Enemy has [enemy_hp] left!" #print in percentages instead, but still retain the 4246 max hp for when taking dmg etc.
     
Last edited by Mikasa01 on Fri Jul 17, 2020 7:56 pm, edited 1 time in total.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Converting a number to percentage

#2 Post by RicharDann »

You'll need to do the math beforehand and save that to another variable. Something like:

Code: Select all

label start:
    $ enemy_hp_percent = int(float(enemy_hp) / float(enemy_max_hp) * 100)

    "Enemy has [enemy_hp_percent] left!"
The most important step is always the next one.

Mikasa01
Newbie
Posts: 13
Joined: Sat Jul 11, 2020 1:01 pm
Contact:

Re: Converting a number to percentage

#3 Post by Mikasa01 »

RicharDann wrote: Fri Jul 17, 2020 7:36 pm You'll need to do the math beforehand and save that to another variable. Something like:

Code: Select all

label start:
    $ enemy_hp_percent = int(float(enemy_hp) / float(enemy_max_hp) * 100)

    "Enemy has [enemy_hp_percent] left!"
That works great! Thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]