Max and minimum on varibles

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
User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Max and minimum on varibles

#1 Post by DragonKnight »

I know I seen this somewhere before on this forum but I can't find it. I need to know how you can calculate the min and the max of variables. I have a variables that can go from 0 to 100. I need to find that ,in or max of the variables and stop it if it goes past the min or max.



example:
Mom Favorite = 98
down the line you add the varibles
$ mom_favorite += 5
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Max and minimum on varibles

#2 Post by Ocelot »

One way to do that:

Code: Select all

init python:
    def clamp(n, smallest, largest): 
        return max(smallest, min(n, largest))

# Later, after each variable change:
$ mom_favorite += 5
$ mom_favorite = clamp(mom_favorite, 0, 100)
Other way is to make some kind of BoundedValue class and use it. It is pretty simple, but you will need to know some Python to make it.
< < insert Rick Cook quote here > >

User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Re: Max and minimum on varibles

#3 Post by DragonKnight »

Thank you!!!!!!!!!
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

Post Reply

Who is online

Users browsing this forum: piinkpuddiin