How to keep a numerical score as saved data upon restarting the game?

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
meliyuu
Newbie
Posts: 4
Joined: Wed Apr 04, 2018 2:03 pm
Contact:

How to keep a numerical score as saved data upon restarting the game?

#1 Post by meliyuu »

I am trying to make a very simple scoreboard. There are four buttons and when it is pressed, the score increases. I want to be able to exit the game and reload with that data still saved instead of it reverting back to the default score. I thought maybe if I just saved the game, this would work, but it doesn't keep the score.

Thanks for any help. This is the code I have so far:

Code: Select all

default hydra=10
default hplus=5
default max_hydra=5000
default hclicked = True

default arachne=10
default aplus=5
default max_arachne=5000
default aclicked = True

default minotaur=10
default mplus=5
default max_minotaur=5000
default mclicked = True

default cerberus=10
default cplus=5
default max_cerberus=5000
default cclicked = True

screen clicker:
    button:
        text "[hydra]" size 40
        background "#000"
        xpos .5
        ypos .1
        xysize(100, 100)
        action [SetVariable("hclicked", True), If(hydra >= max_hydra, true=Jump("win"), false=SetVariable("hydra", hydra + hplus))]
    button:
        text "[arachne]" size 40
        background "#000"
        xpos .5
        ypos .3
        xysize(100, 100)
        action [SetVariable("aclicked", True), If(arachne >= max_arachne, true=Jump("win"), false=SetVariable("arachne", arachne + aplus))]
    button:
        text "[minotaur]" size 40
        background "#000"
        xpos .5
        ypos .5
        xysize(100, 100)
        action [SetVariable("mclicked", True), If(minotaur >= max_minotaur, true=Jump("win"), false=SetVariable("minotaur", minotaur + mplus))]
    button:
        text "[cerberus]" size 40
        background "#000"
        xpos .5
        ypos .7
        xysize(100, 100)
        action [SetVariable("cclicked", True), If(cerberus >= max_cerberus, true=Jump("win"), false=SetVariable("cerberus", cerberus + cplus))]



label start:
    call screen clicker



User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to keep a numerical score as saved data upon restarting the game?

#2 Post by Alex »

Try this - https://www.renpy.org/doc/html/save_loa ... after-load
And also read the whole section about saving.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to keep a numerical score as saved data upon restarting the game?

#3 Post by trooper6 »

I have a Question. Do you want the new scores to be retained even if you start a brand new game? So that if Person A plays your game and gets 100 minotaur points and Person B starts a brand new game they will start their new game with 100 minotaur points as well?

If that is what you want, then you want persistent data. Rather than:

Code: Select all

default minotaur = 10
do

Code: Select all

define persistent.minotaur = 10
However, if you just want the data saved within the game...so for example if you save the game and come back to it later, the score remains how it was...then you just need to save your game. Your current code never gives you a place to do that. Try this version of your code:

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define p = Character('Player', color="#c8ffc8")
define li = Character('Love Interest', color="#c8ffc8")

default hydra=10
default hplus=5
default max_hydra=5000
default hclicked = True

default arachne=10
default aplus=5
default max_arachne=5000
default aclicked = True

default minotaur=10
default mplus=5
default max_minotaur=5000
default mclicked = True

default cerberus=10
default cplus=5
default max_cerberus=5000
default cclicked = True

screen clicker:
    style_prefix "clicker"
    vbox:
        null height 20
        xalign 0.5
        spacing 20
        textbutton "[hydra]":
            text_size 40
            background "#aaa" #"#000"
            xysize(100, 100)
            action [SetVariable("hclicked", True), If(hydra >= max_hydra, true=Jump("win"), false=SetVariable("hydra", hydra + hplus))]
        button:
            text "[arachne]" size 40
            background "#aaa"
            xysize(100, 100)
            action [SetVariable("aclicked", True), If(arachne >= max_arachne, true=Jump("win"), false=SetVariable("arachne", arachne + aplus))]
        button:
            text "[minotaur]" size 40
            background "#aaa"
            xysize(100, 100)
            action [SetVariable("mclicked", True), If(minotaur >= max_minotaur, true=Jump("win"), false=SetVariable("minotaur", minotaur + mplus))]
        button:
            text "[cerberus]" size 40
            background "#aaa"
            xysize(100, 100)
            action [SetVariable("cclicked", True), If(cerberus >= max_cerberus, true=Jump("win"), false=SetVariable("cerberus", cerberus + cplus))]
        textbutton "End" action Return()

style clicker_button is button
style clicker_button_text is button_text

style clicker_vbox:
    xalign 0.5
    ypos 270
    yanchor 0.5

    spacing gui.choice_spacing

style clicker_button is default:
    properties gui.button_properties("choice_button")
    activate_sound "click.wav"

style clicker_button_text is default:
    properties gui.button_text_properties("choice_button")

label start:
    "Default scores. Hydra: [hydra]. Arachne: [arachne]. Minotaur: [minotaur]. Cerberus: [cerberus]."
    "Now we'll call our screen"
    call screen clicker
    "The game continues. Current Scores. Hydra: [hydra]. Arachne: [arachne]. Minotaur: [minotaur]. Cerberus: [cerberus]."
    "Save your game here. Quit the game and then load it."
    "Are you back? Note the scores are the same ones after the click."
    "Hydra: [hydra]. Arachne: [arachne]. Minotaur: [minotaur]. Cerberus: [cerberus]."
    "Game over."
    return

A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], plastiekk