[SOLVED] Issues with saving actually not saving everything

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.
Message
Author
Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

[SOLVED] Issues with saving actually not saving everything

#1 Post by Khef »

Hi.
So I've been playing around with Ren"py recently, and having fun with it.

But I'm running into a strange issue with the saving feature, and I haven't been able to find a solution in the documentation.
I'm not sure how to explain it, and english isn't my native language so please bear with me as I try to explain.

Basically, I'm "working" on a game with somewhat rpg-ish elements : namely, plenty of variables.
Problem is, the changes I make to said variables are only saved up to a precise point. Everything that happens afterwards is not taken into account by the saving mechanism.

To go into the details a bit more : I have the player go through a sort of character creation process at the very beginning. It works beautifully. It saves perfectly.
Everything that happens later on, strangely enough, doesn't.
I know the changes that happen after that creation are effective : the sort of "character sheet" I've put together show the modified values, as they should be. Everything works fine, all in all. Until I save.
Because once I save, and then reload, I'm back to the values as they were straight out of the creation. Even if the first time I save is hours and plenty of modifications after the creation.

I'm guessing I've made a silly mistake somewhere, as I'm new to Ren'py, and not much of a coder to begin with.
But right now I can't make sense of it, and I'd like to solve that before going any further into the makings of the game.

One thing I know which might help is that character creation is a bunch of "called" functions where part (but not all) of what comes later is "jumped" to, what I envision for the game being somewhat non-linear (and overly ambitious, but that's another issue :p).
Could that be related ?

Hope someone can enlighten me, and thanks in advance.
Last edited by Khef on Sat Nov 02, 2013 5:45 am, edited 3 times in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#2 Post by xela »

You can write your classes and functions in init but make sure to declare them in labels... Saving is actually really well explained here: http://www.renpy.org/doc/html/save_load_rollback.html

Basically all that you have to do is to move character creation to "start" or any other label and it'll be fine.
Like what we're doing? Support us at:
Image

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Issues with saving actually not saving everything

#3 Post by Elmiwisa »

Do you use classes for your variables? Do you use store.object or python.RevertableObject if you do use classes?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#4 Post by xela »

Elmiwisa wrote:Do you use classes for your variables? Do you use store.object or python.RevertableObject if you do use classes?
Even if he had inherited from Python's object or nothing at all, it would only have effected rollback, not saving. Serializing will work fine either way.
Like what we're doing? Support us at:
Image

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: Issues with saving actually not saving everything

#5 Post by Khef »

I really kind of am a noob when in comes to coding, as I implied earlier : I know basic algorithms , but I can't use classes. I don't know how they work (and have yet to find an easy enough tutorial).

So no, just good old, simple variables for now. They fit my needs for now, so I see no need to overcomplexify stuff just yet. I may come back and change stuff later but that's for another time. And not the issue.

Functions are in labels of course, as I know that much. As I said, most of what I've done so far works. I'm just curious about why about half of it doesn't save.
Most importantly, I can't see the difference between the parts that work and do save, and the parts that also work and don't.

Thanks for the link, but I'd read that already. Should have mentioned it, my bad. If the answer is there, I missed it, I'm afraid.

I'd include more info, but I don't know where to start.
A short explanation on how the thing works, maybe.
- Variables are declared in init, and receive an initial value.
- They're updated a first few times during the character's creation. In the usual, basic way : $ var += x, that kind of things. Those changes are saved.
- Then comes the rest of the game, where they can be updated again, in the same exact fashion. Except those changes aren't saved, for some reason.

Thanks for the answers though. That was fast.


Edit : ah what the hell, I'll just put some code in, it'll be more explicit.
So, my start looks like this :

Code: Select all

label start:
    $ show_button_overview_menu = False
    $ show_button_whatnext_menu = False

    scene white
    window show
    call charcrea
    call showintro
    call whatnext
    window hide
charcrea works so I won't go into details, but it's basically a bunch of simple stuff like :

Code: Select all

label bodycrea:
#choosing gender
menu:
    "I'm what they call a strapping young lad, I guess.":
        $ pc_gender = "male"
    "I'm a young maiden, nothing special here.":
        $ pc_gender = "female"

# setting basic bodyshape
#height
menu:
    "I am fairly tall.":
        $ pc_height = 1.85
        "You are quite tall, towering at 1.85 m in height"
    "I\'m of average height":
        $ pc_height = 1.70
        "You\'re neither tall nor short, standing at 1.70m"
    "I\'m kinda short":
        $ pc_height = 1.55
        "You\'re short, at barely 1.55 m in height"

etc...
Ingame changes are along the same lines :

Code: Select all

label go_home:
    menu:
        "You decide to spend some time at your flat. But what are you gonna do there ?"
        "In fact, I'm gonna rest for a bit. Time to relax a little.":
            call rest1hour
            "You spend an hour not doing much, just laying back and enjoying the comfort of your humble flat."
        "I'm tired. Time to sleep.":
            call sleep
        "Hmm ... I'll exercise a bit.":
            call advance1hour
            "You work up a good sweat. Tiring, but if you keep this up, results should show. A good shower to clean up and you're ready to go."
            $ pc_strength += 1
            $ pc_fortitude += 1
            $ pc_fatigue += 4
    
    call whatnext
Except in those examples, upon saving, the strength, fortitude and fatigue changes (or changes to height or whatever as long as it happens after charcrea) aren't included. That's my problem.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#6 Post by xela »

- Variables are declared in init, and receive an initial value.
Declare those in labels and you'll be fine.
Like what we're doing? Support us at:
Image

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: Issues with saving actually not saving everything

#7 Post by Khef »

Alright, so I must doing something seriously wrong, because that doesn't solve the issue.

I've put all my variable declaring in a label, called it on start (*) first thing ... and the problem remains, identical as ever.
Some changes saved, some not.

(*) I'm guessing that's not the right place at all, is it ?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#8 Post by xela »

Khef wrote:Alright, so I must doing something seriously wrong, because that doesn't solve the issue.

I've put all my variable declaring in a label, called it on start (*) first thing ... and the problem remains, identical as ever.
Some changes saved, some not.

(*) I'm guessing that's not the right place at all, is it ?
I don't understand this post.

Did you make sure that there not a single one of your variables is declared in the init?
Like what we're doing? Support us at:
Image

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: Issues with saving actually not saving everything

#9 Post by Khef »

Certain. I double checked. Triple, even. Not sure how to explain any further, really.

I have all my variables in a single label, and that label being called is now the first thing to happen in "label start:".
Because it's much easier for me if those have an initial value before anything else happens (I can't even really work around that considering what I want to do, but I doubt it has anything to do with my issue).

The game still only saves changes up to a point.
Bottom line is still : some changes I make to my vars are saved, some aren't.
And I can't make sense of it.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#10 Post by xela »

Khef wrote:Certain. I double checked. Triple, even. Not sure how to explain any further, really.

I have all my variables in a single label, and that label being called is now the first thing to happen in "label start:".
Because it's much easier for me if those have an initial value before anything else happens (I can't even really work around that considering what I want to do, but I doubt it has anything to do with my issue).

The game still only saves changes up to a point.
Bottom line is still : some changes I make to my vars are saved, some aren't.
And I can't make sense of it.

No idea than... doesn't seem possible. Maybe something to do with "call" statements you keep using, I've never used them myself but from what I've read, they shouldn't cause these issues either.
Like what we're doing? Support us at:
Image

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: Issues with saving actually not saving everything

#11 Post by Khef »

Ah well, thanks for trying.

I'll try and get rid of those calls when I get more time, see if that changes anything.
I'm guessing you use jumps instead (never quite got the difference anyway) ? Or is there another method I don't know ?

And here's to hoping someone else will a an idea. I don't want to have to give up on this little project of mine.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Issues with saving actually not saving everything

#12 Post by xela »

As I've said, I doubt it's the call statements. I use jump, yes (you return to previous label after call, jump doesn't do that for you). You could alternately upload your project/working part of your project somewhere and post a link. Anyone with experience here will be able to tell you exactly what's going on if complete code is available.
Like what we're doing? Support us at:
Image

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: Issues with saving actually not saving everything

#13 Post by Khef »

Well, well, well. What do you know.
I changed the code to rely mostly on jumps, and it solved the problem.
So I now better understand how things work around here, AND I finally solved my issue. It even kind of makes sense now.
A good, if laborious, day. In the end.

Thanks for your patience, xela, much appreciated.

Khef
Newbie
Posts: 17
Joined: Fri Oct 18, 2013 4:51 am
Contact:

Re: [SOLVED] Issues with saving actually not saving everythi

#14 Post by Khef »

So yeah, hi, I'm back.

Turns out the issue is not as solved as I once thought it to be.
I'm pretty much back to where I started, with the whole ordeal making as little sense as ever.

I used to think I knew where the problem was coming from. Turns out I was just lucky for a few tries.
Now, considering that sometimes the saves will be fine and sometimes they won't, with the same exact code, and the same exact use of the "game" - or at least without my identifying a difference ... I'm at a complete loss. Especially considering the simplicity of my "code".

To sum up my problem, so you don't have to re-read everything : the code works, my variables are changed, I can see it because I have them displayed on screens, texts and whatnot. They are shown modified as they should be. Everything works fine.
Until I save.
And load.
Because the changes are not saved, and the variables are back to their original, previous values.
Unless they're not, because sometimes the changes are actually saved.
And I don't know why the behavior changes from one time to another

For those interested in more details, basically, the code goes like this.
(Everything before "whatnext" works. And saves. That's the only reliable part of the whole thing.
Not surprising, since it's just a bunch of variable being set, intro text, that sort of stuff.) :

Code: Select all

label start:

    call declarevars               #that's just a bunch of $ x = y, and part of what works
    $ show_button_overview_menu = False
    $ show_inventory = False

    scene white
    window show
   
    call charcrea                  #this is what works and is saved flawlessly. Again, very simple $ x += y kinda stuff
    call showintro                 #just a few paragraphs of text
    jump whatnext               # the beginning of all that is wrong, I guess. see below.

#the base of everything, pretty much. Where the player decides what he will do next, and where he always jumps back.

label whatnext:
    nvl clear
    $ show_button_overview_menu = True
    menu:
        "So, what are you gonna do next ?"
        "I'll visit the Merchant District. Not sure I'm going to buy stuff, but I should be able to have fun there.":
            $ show_button_overview_menu = False
            jump go_merchd
        "I think I'll just stay home. There's lots of stuff I can do from here. Rest, train, play, whatever.":
            $ show_button_overview_menu = False
            jump go_home

#let's go_merchd for the example, since it's one of the ways I test it and notice the issue. All my shops are basically the same too, so no point in putting them all here.

label go_merchd:
    nvl clear
    if been_merchd == False:
        "Placeholder MerchantDistrict, 1st visit.{nw}"
        $ been_merchd = True
    else:
        "Placeholder Merchant District, 2nd visit and later.{nw}"
    menu :
        "So, what are you gonna do now that you\'re here ?"
        "Let me find a General Store, I got some common stuff to buy":
            "Placeholder for general Store."
            jump go_genstore
        "\"The Paramagical Emporium\". Well, a place like that should have interesting stuff.":
            jump go_emporium
        "Actually I've changed my mind. I'll do something else instead.":
            jump whatnext

#next, the emporium

label go_emporium:
    nvl clear
    if been_emporium == False:
        $ been_emporium = True
        "Placeholder for Emporium, first visit.{nw}"
    else:
        "Placeholder for Emporium, second and subsequent visits.{nw}"
    menu:
        "Apparently, there are two kinds of things you cand find here : Enchanted Objects and alchemy consumables. What are you interested in most ?"
        "The enchanted stuff, right now.":
            jump emp_enchanter
        "The consumables seem more tempting. Let's see what they've got.":
            jump emp_alchemy
        "This place has nothing I want, I'll just leave.":
            call advance1hour
            jump whatnext

#the only reason I separated the submenus in different functions was to try and solve the saving issue. It didn't work at all but for the sake of exactitude, since that's how my code is right now ...

label emp_alchemy:    
    menu:
        "This shop has much to offer. So, what are you interested in ?"
        "\"Healing Potion\". Just what I needed.":
            if pc_money >= 100:
                $ pc_money -= 100
                $ consumables.append("healpot")
            else:
                "You don't have that much money."
        "Hmm ... tempting stuff, but not what I'm looking for today.":
            pass
    jump go_merchd

#I went with go_merchd for ergonomy purposes, but had go_whatnext earlier one and that didn't work either. Or more precisely, it worked, but the append wasn't saved.
It's worth noting that I only recently switched to the list and append/remove method, but even when I was using the terrible "$ var += 1" way, the problem was the same.
Also, other parts are still just "$ varstring = x", and they don't work either.

I used to think it was because I always come back to "whatnext", which means it kinda loops and ren'py doesn't save what happens in loops. Or so I think I read somewhere in the doc, can't seem to find it now. Maybe I misunderstood something.
Anyways. Even then, it should never work, not do the fifty-fifty thing it almost does now (not quite 50-50, actually, there are more fails than successes, but still).

I've now spent actual days fighting this thing, and still find myself completely clueless about what's going on. Every time I think I've solved it, it comes back.
So I really need help here.
And I just hope someone will point out the silly mistake I'm no doubt making.



Since this is a hell of a long post, I'll apologize again for any language weirdness, as english isn't my native language.
Sorry about that.

Edited to add label start:, just in case.
Last edited by Khef on Wed Oct 30, 2013 4:07 pm, edited 2 times in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [SOLVED] Issues with saving actually not saving everythi

#15 Post by xela »

Khef wrote:I used to think it was because I always come back to "whatnext", which means it kinda loops and ren'py doesn't save what happens in loops. Or so I think I read somewhere in the doc, can't seem to find it now. Maybe I misunderstood something.
Anyways. Even then, it should never work, not do the fifty-fifty thing it almost does now (not quite 50-50, actually, there are more fails than successes, but still).
There doesn't seem to be anything wrong with the code you've posted, there is no chance in hell that jumping to the same label causes problems, I am working on a much more complicated game that yours and it keeps jumping to the same labels over and over again, never had any issues with saving.

You're messing something up in init or resetting variables somewhere in the code, it's the only thing that makes sense.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: No registered users