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.
Hi there! So as the subject title says, I'm trying to calculate a percentage of a stat in python but at the same time making sure that it never ends up dividing by zero. What I was trying to achieve is:
label start:
$ joker = 0 # Personality stat
$ joker_max = 0 # Maximum value of personality stat
... ...
# Every time the player comes across an menu that has an option with a joker personality stat in it, joker_max increases by 1
label menu_option_that_has_a_joker_in_it:
$ joker_max += 1
menu:
"Tell a joke":
$ joker += 1
"Don't tell a joke":
pass
jump route_rejoin
# If the player doesn't come across an option with a joker personality in it, joker_max remains the same.
label alternate_route_that_doesnt_have_joker_opt_in_it:
jump route_rejoin
... ...
# The problem arises here. If the player hasn't come across a route with a joker option in it, it'll end up dividing by 0 and lead to an undefined error...
label route_rejoin:
if joker/joker_max * 100 > 50:
jump joker_dialogue
else:
jump normal_dialogue
Maybe I'm just bad at math equations or asking for the impossible, but is there a way that I can rephrase the last part so that it won't ever lead to a division by 0 (and thus an undefined error)?
Thanks in advance!
Last edited by AsHLeX on Mon May 16, 2022 8:16 am, edited 1 time in total.