Points storage

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
bokuman
Regular
Posts: 65
Joined: Tue May 23, 2017 1:08 pm
Projects: VN 789
Deviantart: bokuman
Contact:

Points storage

#1 Post by bokuman »

I have a system points on my project, but im not sure why those points are not saved, what problems i could need to check for this issue?

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Points storage

#2 Post by _ticlock_ »

You probably defined the variable in init block. Let's say you have variable points. You can do something like this:

Code: Select all

default points = 0 

label start:
    $ points = 4
    "Current points are - [points]"
    "Try save and load"
    "Current points are - [points]"

bokuman
Regular
Posts: 65
Joined: Tue May 23, 2017 1:08 pm
Projects: VN 789
Deviantart: bokuman
Contact:

Re: Points storage

#3 Post by bokuman »

I think the problem is more complex lol

i use this to define somethings and points. on my screens

Code: Select all


init python:
    def no_rep_rand(lst, curr):
        r = curr
        while r == curr:
            r = renpy.random.choice(lst)
        return r
    class waifu:
        def __init__(self, name, dir, act, off):
            self.name = name
            self.dir = dir
            self.act = act
            self.off = off
            self.avt = "normal"
            self.points = 0
        def pts(self, x):
            if self.points + x > -2001 and self.points + x < 2001:
                self.points += x
        def change(self, x):
            self.avt = x
and i define later the variables on this way w_girl1.points etc, because there are more girls, make sense?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Points storage

#4 Post by Imperf3kt »

Did you remember to default the variables for the points though?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Points storage

#5 Post by _ticlock_ »

As Imperf3kt said, do you 'define' class instance like this?

Code: Select all

default w_girl1 = waifu( 'name', ...)

bokuman
Regular
Posts: 65
Joined: Tue May 23, 2017 1:08 pm
Projects: VN 789
Deviantart: bokuman
Contact:

Re: Points storage

#6 Post by bokuman »

is defined on this way

Code: Select all

init python:
    def no_rep_rand(lst, curr):
        r = curr
        while r == curr:
            r = renpy.random.choice(lst)
        return r
    class waifu:
        def __init__(self, name, dir, act, off):
            self.name = name
            self.dir = dir
            self.act = act
            self.off = off
            self.avt = "normal"
            self.points = 0
        def pts(self, x):
            if self.points + x > -2001 and self.points + x < 2001:
                self.points += x
        def change(self, x):
            self.avt = x
define w_girl1 = waifu("girl1", "char/girl1", Jump('girl1_chapter'), (-1, -1))
define w_girl2 = waifu("girl2", "char/girl2", Jump('girl2_chapter'), (0, -1))
define w_girl3 = waifu("girl3", "char/girl3", Jump('girl3_chapter'), (1, -1))
define w_girl4 = waifu("girl4", "char/girl4", Jump('girl4_chapter'), (-1, 0))
define w_girl5 = waifu("girl5", "char/girl5", Jump('girl5_chapter'), (1, 0))
define w_none5 = waifu(" ", "char/none", Jump('none_chapter'), (-1, 1))
define w_none6 = waifu(" ", "char/none", Jump('none_chapter'), (0, 1))
define w_none7 = waifu(" ", "char/none", Jump('none_chapter'), (1, 1))

#define w_random = waifu("Random", "char/random", Jump('amber_chapter'), (0, 0))
#define w_player = waifu("Player", "char/player", Jump('amber_chapter'), (1, 1))
#define w_amber = waifu("Amber", "char/amber", Jump('amber_chapter'), (1, 1))

define waifus = [
    w_girl1,
    w_girl2,
    w_girl3,
    w_girl4,
    w_girl5,
    w_none5,
    w_none6,
    w_none7,
]
i have a select menu.

and variables are w_girl1.points, w_girl2.points etc

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Points storage

#7 Post by _ticlock_ »

That is the problem. Look at documentation https://www.renpy.org/doc/html/python.h ... -statement.
Basically define is equivalent to:

Code: Select all

init python:
    w_girl1 = waifu("girl1", "char/girl1", Jump('girl1_chapter'), (-1, -1))
You need to use default so the class instance will be saved and will not be rewritten at initialization:

Code: Select all

default w_girl1 = waifu("girl1", "char/girl1", Jump('girl1_chapter'), (-1, -1))

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot]