[SOLVED] Save/load does not load the proper data

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
Ace94
Regular
Posts: 113
Joined: Sat Apr 08, 2017 4:22 pm
Contact:

[SOLVED] Save/load does not load the proper data

#1 Post by Ace94 »

Can anyone help please? I am doing an HP bar and at some point in the story the player takes damage like this:

Code: Select all

    $ player.mc_hp = max(0, player.mc_hp-45)
    "You step on a spike and take 45 damage."

    $ player.mc_hp = max(0, player.mc_hp-30)
    "You trip and take 30 damage."
And this works great, but if the player saves and loads an older save for some reason it doesn't load back the proper HP of what the player had at the time. So if they go pass this point and load a save prior to this point they will load with 75 less HP. Please! Can anyone help? I've been looking all day for someone with similar issue and I can't find anything!
Last edited by Ace94 on Thu Jul 09, 2020 9:57 am, edited 1 time in total.

User avatar
renardjap
Regular
Posts: 75
Joined: Sun Aug 05, 2018 1:08 pm
Location: France ! Cocorico
Contact:

Re: Save/load does not load the proper data

#2 Post by renardjap »

Hi
Could you show more code please?

Ace94
Regular
Posts: 113
Joined: Sat Apr 08, 2017 4:22 pm
Contact:

Re: Save/load does not load the proper data

#3 Post by Ace94 »

Code: Select all

init -1 python:
    import renpy.store as store
    import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
    inv_page = 0 # initial page of the inventory screen
    item = None

    class Player(renpy.store.object):
        def __init__(self, name, mc_max_hp=100, mc_max_mp=0, element=None, healthpot=None):
            self.name=name
            self.mc_max_hp=mc_max_hp
            self.mc_hp=mc_max_hp
            self.mc_max_mp=mc_max_mp
            self.mp=mc_max_mp
            self.element=element
            self.healthpot=healthpot
    player = Player("[mc]", 100, 50)
and the bar:

Code: Select all

screen mc_hp_screen:
        $renpy.transition(dissolve)
        bar align (0.125, 0.10) value AnimatedValue(player.mc_hp, player.mc_max_hp, delay=1.0) style "hp_slider"
        text "[player.mc_hp]%" size 26 align (0.172, 0.123) style "hp_bar_percentage"

Code: Select all

label start:
    $ mc = renpy.input("", length=10, with_none=None, pixel_width=None)
    if mc == "":
        "Invalid name."
        jump start

    show screen inventory_button()
    show screen mc_hp_screen

Eliont
Regular
Posts: 111
Joined: Thu Aug 06, 2009 6:51 am
Completed: Begin of Evangelion, SAO - Smile of the black cat, SAO - Project "Ceramic Heart", Time for Dragons
Location: Russia
Contact:

Re: Save/load does not load the proper data

#4 Post by Eliont »


Ace94
Regular
Posts: 113
Joined: Sat Apr 08, 2017 4:22 pm
Contact:

Re: Save/load does not load the proper data

#5 Post by Ace94 »

Eliont wrote: Thu Jul 09, 2020 8:23 am Try to use https://www.renpy.org/doc/html/save_loa ... after-load
I tried that. It didn't fix the issue unfortunately. :(

This is what happens in a nutshell:

Code: Select all

    #Player saves the game here."
    "Walking down the path..."
    $ player.mc_hp = max(0, player.mc_hp-45)
    "You step on a spike and take 45 damage."

    $ player.mc_hp = max(0, player.mc_hp-30)
    "You trip and take 30 damage."
    
    #Player loads save here."
The loaded save should be the player at 100% hp, but instead the player will be at 25% and if he continues the game he will be at 0 at that point. I want to point out that if I quit the whole game and THEN load the save file this doesn't happen. It only does it when it is played without stopping/relaunching the game. I really don't understand what the issue is.

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Save/load does not load the proper data

#6 Post by drKlauz »

Create player after start label.

Code: Select all

label start:
  $player=Player()
Objects (including lists&dicts) created in init block are not saved.

https://www.renpy.org/doc/html/save_load_rollback.html

P.S.: Or use

Code: Select all

default player=Player()
Tho i personally prefer using something like

Code: Select all

label init_game:
  $player=Player()
  return

label start:
  call init_game
  #content starts here
It allow more flexible variable initialization.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Ace94
Regular
Posts: 113
Joined: Sat Apr 08, 2017 4:22 pm
Contact:

Re: Save/load does not load the proper data

#7 Post by Ace94 »

drKlauz wrote: Thu Jul 09, 2020 9:45 am Create player after start label.

Code: Select all

label start:
  $player=Player()
Objects (including lists&dicts) created in init block are not saved.

https://www.renpy.org/doc/html/save_load_rollback.html

P.S.: Or use

Code: Select all

default player=Player()
Tho i personally prefer using something like

Code: Select all

label init_game:
  $player=Player()
  return

label start:
  call init_game
  #content starts here
It allow more flexible variable initialization.
Oh, my god! It worked! Thank you so so so much! :)

Post Reply

Who is online

Users browsing this forum: No registered users