Player Perk Implementation [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.
Message
Author
DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Player Perk Implementation [unsolved]

#16 Post by DapNix »

Guys, I think you are now allowed to bring out your Dummy-Clubs and hit me as hard as you can.

I thought I could simply click the button and then save/load. But you have to progress dialogue by clicking before saving... Is there a way to make it so that this isn't necessary though?

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Player Perk Implementation [unsolved]

#17 Post by philat »

Dapnix: To be honest, I was wondering if it was that. I was reading the saving/loading page on the wiki and that seemed a possible cause. http://www.renpy.org/doc/html/save_load ... after-load seems applicable, but I've never used this feature, so let me know how it goes.
trooper6 wrote:I think yours works because of the store.Object. Without it, the function is not going to be able to get access to the right "player" variable, and will probably just make up its own that doesn't exist outside of that function.
Even though I threw the store.object thing in there as a last ditch tip, and tend to put it in my scripts anyway (yes, I'm a CYA type of person :P) afaik, classes in rpy scripts inherit from renpy.store.object by default.

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Player Perk Implementation [unsolved]

#18 Post by DapNix »

Oh my god, yes! Thank you so much philat! My perk screen is split into two parts, as soon as you enter the first screen I added the "$ renpy.retain_after_load()" and now, if I just leave the screen and save/load, the values are saved! Bunch of thanks to both of you for sticking with me on this :)

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: Player Perk Implementation [unsolved]

#19 Post by trooper6 »

Okay, I just tried an experiment, where I created three different versions of the Fighter/Perk combo.
1) with store.Object.
2) with no store.Object, but with global
3) with no store.Object and no global.

Then I made one of each and tested it with the saving. Here is what I found...this might be interesting.

1) If you click the Update button and advance the text, all 3 save no problem!
2) If you click the Update button and don't advance, #2 and #3 save, but #1 doesn't

philat, if you use my script, do you get the same results? If so, what do you think that is about?

Code: Select all

screen upgrade():
    textbutton "Upgrade" action [Atk1.upgrade, Atk2.upgrade, Atk3.upgrade, Hide("upgrade")]

init python:
    class Fighter(store.object):
        def __init__(self, name, power):
            self.name = name
            self.power = power

    class Perk(store.object):
        def __init__(self, name, power):
            self.name = name
            self.power = power
        def upgrade(self):
            player.power += self.power
            
    class Fighter2():
        def __init__(self, name, power):
            self.name = name
            self.power = power

    class Perk2():
        def __init__(self, name, power):
            self.name = name
            self.power = power
        def upgrade(self):
            global player2
            player2.power += self.power

    class Fighter3():
        def __init__(self, name, power):
            self.name = name
            self.power = power

    class Perk3():
        def __init__(self, name, power):
            self.name = name
            self.power = power
        def upgrade(self):
            player3.power += self.power
#The game starts here.
label start:

    $ player = Fighter("Player 1", 10)
    $ Atk1 = Perk("Attack 1", 10)
    
    $ player2 = Fighter2("Player 2", 20)
    $ Atk2 = Perk2("Attack 2", 20)
    
    $ player3 = Fighter3("Player 3", 30)
    $ Atk3 = Perk3("Attack 3", 30)
    
    show screen upgrade

    "Player power: [player.power]\n
     Player2 power: [player2.power]\n
     Player3 power: [player3.power]"
    
    "Now Press Upgrade"
    
    "Player power upgrade: [player.power]\n
     Player2 power upgrade: [player2.power]\n
     Player3 power upgrade: [player3.power]"
    
    "save/load here"
    "Player power after load: [player.power]\n
    Player2 power after load: [player2.power]\n
    Player3 power after load: [player3.power]"
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

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Player Perk Implementation [unsolved]

#20 Post by philat »

Haha, jesus christ. I have no idea what is going here. Yes, I get the same results as you, and apparently so I shouldn't be supplying store.object just to be on the safe side.

I mean, it must be some sort of difference in how the screen interacts with the relevant field of the Fighter object, but I can't see what at all would be different. Bizarro.

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: Player Perk Implementation [unsolved]

#21 Post by trooper6 »

(I don't know if this should be in a different thread, but I'll keep it here for now)

philat, have you put the code on the renpy.retain_after_load() page into a project?
Just did...and it seems a bit wonky to me.

Here is the code I put in a new project:

Code: Select all

screen edit_value():
    hbox:
        text "[value]"
        textbutton "+" action SetVariable("value", value + 1)
        textbutton "-" action SetVariable("value", value - 1)
        textbutton "+" action Return(True)

# The game starts here.
label start:
    $ value = 0
    $ renpy.retain_after_load()
    call screen edit_value
    
    e "Value: [value]."


    return
I did two different things:

Experiment 1:
1. Start Game
2. Click on the Add button 4 times
3. Hit Escape to bring up the save menu and save the game.
4. Hit the Return button (Value is still 4)
5. Click the exit button, I see Eillen telling me Value 4.
6. Game ends.
7. Quit the game and relaunch.
8. Load my Save and I am brought to the value screen showing 4.
9. Click the exit button, I see Eillen telling me Value 4.
10. I try rolling back & forward and everything is also good.
11. Game ends.

That is good, right?

Okay, Experiment 2.
1. Start Game
2. Click on the Add button 4 times
3. Click the exit button, I see Eillen telling me Value 4.
4. I try rolling back & forward and I get value of 0.

Experiment 3.
1. Start Game
2. Click on the Add button 4 times
3. Click the exit button, I see Eillen telling me Value 4.
4. I click Save on the quick menu and save
5. I click return and come back to the game, I see Eileen telling me Value 4.
6. Game ends.
7. Quit the game and relaunch.
8. Load my Save and I see Eillen telling me Value 4.
9. I try rolling back & forward and still I get 0 for value.
10. Game ends.

Neither of these experiments work properly. Any ideas or should I make this question its own thread?
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

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Player Perk Implementation [SOLVED]

#22 Post by philat »

Hmm, might be worth it to move to a different thread, but here's my 2 cents.

The documentation explains that renpy.retain_after_load() saves what happened in the screen and binds it to the current statement (in this case, the start of the game). But rollback and roll forward will reset this if going PAST the current statement.

Code: Select all

screen edit_value():
    hbox:
        text "[value]"
        textbutton "+" action SetVariable("value", value + 1)
        textbutton "-" action SetVariable("value", value - 1)
        textbutton "+" action Return(True)

# The game starts here.
label start:
    $ value = 0

    "filler"

    $ renpy.retain_after_load()
    call screen edit_value
    
    e "Value: [value]."
    return
If you do your same experiment 1, load that save, roll all the way back to filler, then roll forward, you get 0 again. Because the saved 4 was tied to the most current statement (which in this case would be the line with $ renpy.retain_after_load(), I think? Tbh I still just guess with most of the more mechanical python-y questions on how renpy works as an engine).

I've honestly never made a very complex game before -- the games I finished were super simple and in cases where I had more complex mechanics in mind, those projects were relegated to perpetually-WIP-status purgatory, so I've never dealt with save/load/rollback problems much. I'm sure others who have done more complex work for larger scale projects would have a better answer. Or PyTom :P

Post Reply

Who is online

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