Page 1 of 1

Maximum points? PLS help me.

Posted: Tue Jan 09, 2018 9:33 am
by tobirama
Hello friends!

I am new to renpy and i try to use luck points in one of my projects.

I want them to be at 100 maximum so i use this in my screens:

r_max = 100
r_luck = 1


adding points works alright but somehow when i reach 100 it goes on to 101 , 102 etc so the r_ thing doesnt seem to work?

pls help me :cry:

Re: Maximum points? PLS help me.

Posted: Tue Jan 09, 2018 9:58 am
by mikolajspy
Your r_max is just another variable and does not do anything on it's own.

You can, however do something like this, right after adding points:

Code: Select all

$r_luck += 1   #Adds points to the variable
if r_luck > r_max:    # if luck points are greater than max value you want to have...
    $r_luck = r_max    # set the luck to the maximum value
or you can write a function, so it check automatically when adding like this (put this code somewhere at top of script)

Code: Select all

init python:
    def Add_luck(n):
        r_luck += n
        if r_luck > r_max:
            r_luck = r_max
and then use it like this where it should be added:

Code: Select all

$ Add_luck(1)
I think this might work

Re: Maximum points? PLS help me.

Posted: Tue Jan 09, 2018 10:20 am
by RicharDann
Adding on to what mikolajspy suggests, I do recommend the function approach as I know it works wonderfully. One question though, shouldn't you use global in the function to change the values?

Code: Select all

init python:
    def Add_luck(n):
        global r_luck, r_max #?
        r_luck += n
        if r_luck > r_max:
            r_luck = r_max
That is, if the r_luck and r_max variables are defined outside of init block, using default, or in the script. Not too sure about that so if I'm wrong I apologize.

Re: Maximum points? PLS help me.

Posted: Wed Jan 10, 2018 9:10 am
by tobirama
Awesome , thank you guys! You helped me alot!