Displaying and remember points made after exiting the game(SOLVED)

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
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Displaying and remember points made after exiting the game(SOLVED)

#1 Post by beastcarving » Tue Feb 04, 2020 6:24 pm

I put this in the screens.rpy under the main_menu

Code: Select all

    text "  Points Made: [made_points]"
In the script

Code: Select all

init:
    $ made_points =0
And I added this to a label

Code: Select all

$ made_points +=1
The problem I'm having is when I press exit on the game and reopen it the points displayed on the Main_menu are at Zero again. How do I make it remember the points that were made?

The other issue I'm having is earning the same points when simply going back to replay a part of the game. I want to make these point count ONCE when you come across one of these:

Code: Select all

$ made_points +=1
just to make earning that point honest without being able to cheat by going back 20 times to win 20 point that you didn't necessary win fairly.
Last edited by beastcarving on Mon Apr 13, 2020 1:55 pm, edited 1 time in total.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Displaying and remember points made after exiting the game(HELP!)

#2 Post by gas » Tue Feb 04, 2020 10:50 pm

The thing you're asking is basically how to have a player overall score, not linked to the single playthrough.
Sond easy but in fact require a number of things.

The fist one is to use a SET() instead of a simple tally counter. A SET() can contain just a single copy of an element.
To have such set work on a global meaning, it should be a persistent.
When you want to deal a point, just add a keyword to the set. You can compute the overall score by counting the elements in the set.

This is a very silly example, but should work.

Code: Select all

label start:
    python:
        if persistent.score == None:
            persistent.score = set()
    e "Welcome to my proxy game!"
    e "Now you'll get a bonus point..."
    $ persistent.score.add("bonus")
    e "If you play multiple times, anyway, your score doesn't increase!"
    $ the_score = len(persistent.score)
    e "Your score is [the_score]!"
    e "Try to launch again the game and see it for yourself."
    
The trick is to use
$ persistent.score.add("x")
with an "x" keyword different all the time, so you don't have sums even after multiple playthrough.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

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

Re: Displaying and remember points made after exiting the game(HELP!)

#3 Post by Imperf3kt » Tue Feb 04, 2020 11:25 pm

Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Displaying and remember points made after exiting the game(HELP!)

#4 Post by gas » Wed Feb 05, 2020 1:35 am

("The problem I'm having is when I press exit on the game and reopen it the points displayed on the Main_menu are at Zero again. How do I make it remember the points that were made?") - isn't that the persistent case of use?
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

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

Re: Displaying and remember points made after exiting the game(HELP!)

#5 Post by Imperf3kt » Wed Feb 05, 2020 2:49 am

gas wrote:
Wed Feb 05, 2020 1:35 am
("The problem I'm having is when I press exit on the game and reopen it the points displayed on the Main_menu are at Zero again. How do I make it remember the points that were made?") - isn't that the persistent case of use?
Yes, and you covered that well.
I should have explained better, but I was referring to the use of init instead of the more preferred way of using define/default
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: Displaying and remember points made after exiting the game(HELP!)

#6 Post by beastcarving » Thu Feb 06, 2020 6:09 am

I'm having a hard time adding and subtracting from the score.
Would I write something like this to deduct from the overall score:

Code: Select all

$ persistent.score.minus(3) = the_score
and to add more than one point at a time would I need to do something like:

Code: Select all

        python:
            if persistent.score == None:
                persistent.score = set()
        $ persistent.score.add(+30)"bonus3") #rather than $ persistent.score.add("bonus3,bonus4",bonus5,bonus6, etc... bonus30)
        $ the_score = len(persistent.score)
Neither of these work. I was wondering how to do something like this.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

Post Reply

Who is online

Users browsing this forum: No registered users