Maximum points? PLS help me.

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
tobirama
Newbie
Posts: 5
Joined: Mon Dec 18, 2017 12:16 pm
Contact:

Maximum points? PLS help me.

#1 Post by tobirama » Tue Jan 09, 2018 9:33 am

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:

mikolajspy
Regular
Posts: 160
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Jake's Love Story
Projects: NEKOKORO
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Maximum points? PLS help me.

#2 Post by mikolajspy » Tue Jan 09, 2018 9:58 am

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

User avatar
RicharDann
Regular
Posts: 120
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Maximum points? PLS help me.

#3 Post by RicharDann » Tue Jan 09, 2018 10:20 am

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.

tobirama
Newbie
Posts: 5
Joined: Mon Dec 18, 2017 12:16 pm
Contact:

Re: Maximum points? PLS help me.

#4 Post by tobirama » Wed Jan 10, 2018 9:10 am

Awesome , thank you guys! You helped me alot!

Post Reply

Who is online

Users browsing this forum: No registered users