A NoRollback class question

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
Aviala
Miko-Class Veteran
Posts: 533
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Love Bug, Lovingly Evil
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

A NoRollback class question

#1 Post by Aviala »

Hey all!

I'm trying to create a class that uses the NoRollback feature of renpy. I think I did exactly the same things as the example states on the bottom of this page: https://www.renpy.org/doc/html/save_load_rollback.html

My code is as follows:

Code: Select all

init python:
    class ChronoSoda(NoRollback):
        def __init__(self):
            self.value = 0

label start:
    default chronosodas = ChronoSoda()
    default chronosodas.value = 1
I added a screen to test if the code works and it says that I have 0 chronosodas. I don't understand - I clearly set it as 1?

Code: Select all

screen test_text2:
    text "[chronosodas.value]"
I'm trying to create a button that lets the player use the Chronosoda to travel back in time (essentially rollback) and not have rollback affect the amount of chronosodas the player has.

Code: Select all

screen chrono:
    imagebutton auto "gui/potion_%s.png" action If(chronosodas.value >= 1 , [SetVariable("chronosodas.value", chronosodas.value-1), Rollback()]) xalign 0.82 yalign 0.95
There is also a choice to create more chronosodas in another part of the game:
$ chronosodas.value += 1

But I never got far enough to test if it works.
I don't understand the usage of define and default properly, but I noticed they need to be used or the game crashes. Could someone help me fix this code? I would really like the time travel potion to be a part of the game; it has roguelite elements so I don't want the player to be able to rollback freely without paying for creating the potion.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: A NoRollback class question

#2 Post by Remix »

You would likely do best using renpy.retain_after_load() for the blocks where chronosodas changes. Probably want to also include it to wrap the crafting so the ingredients cannot be stockpiled by timewarping.
Frameworks & Scriptlets:

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: A NoRollback class question

#3 Post by trooper6 »

Declaring your variables using default/define should be outside of any block, not inside the start block as you have it.
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

User avatar
Aviala
Miko-Class Veteran
Posts: 533
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Love Bug, Lovingly Evil
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Re: A NoRollback class question

#4 Post by Aviala »

Remix wrote: Tue Jan 23, 2018 12:16 pm You would likely do best using renpy.retain_after_load() for the blocks where chronosodas changes. Probably want to also include it to wrap the crafting so the ingredients cannot be stockpiled by timewarping.
I've never used renpy.retain_after_load(), it seems like it could help but I'm not sure how to go about doing it. Any tips on how to use it? I don't really understand how it works even after reading the description. ; _ ; I read it, and it "goes in from one ear and out of the other". I'd really appreciate if you (or someone else) could explain in simple terms how to use renpy.retain_after_load() to do what I need to do?

I'll also try changing where I define the variables like trooper said. But I'm doubtful that it alone would fix the problem?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: A NoRollback class question

#5 Post by Remix »

Aviala wrote: Tue Jan 23, 2018 4:05 pm I've never used renpy.retain_after_load(), it seems like it could help but I'm not sure how to go about doing it. Any tips on how to use it? I don't really understand how it works even after reading the description. ; _ ; I read it, and it "goes in from one ear and out of the other". I'd really appreciate if you (or someone else) could explain in simple terms how to use renpy.retain_after_load() to do what I need to do?
Hmmm, just had a play with it and it seems less versatile that I had imagined...
I had thought the function call would retain altered values after it is called up until the next checkpoint (where things go back to normal again)...
This does not seem to be the case, certainly not in bob standard label type code anyway.

Ignore my idea completely, it doesn't seem viable.

Are you currently fully blocking the in-built rollback and still wanting to use it just when the player has the items?
Have you considered just Jumping back to the last label instead and leaving the rollback system alone?
Frameworks & Scriptlets:

User avatar
Aviala
Miko-Class Veteran
Posts: 533
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Love Bug, Lovingly Evil
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Re: A NoRollback class question

#6 Post by Aviala »

I'm not sure about jumping to the last label - seems a bit unreliable to me, since there's no good way to know how far back in time it'll take the player.
I'm currently not blocking rollback at all; I'm just going to disable the hotkeys for rollback and instead of a quick menu button that says "back" I want to have the potion as a button that basically does the same thing as the "back" button in most renpy games but costs one potion to use.

It seems like the NoRollback class should be just the thing to use since I basically only need that one variable (chronosodas) to not be affected by rollback. But for some reason I can't figure out how to get it to work.

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

Re: A NoRollback class question

#7 Post by philat »

Based on your description, I don't think NoRollback means what you think it means. Look at the example again. By participating in rollback, o.value is fixed at 1 even if you rollback multiple times (i.e., o.value 'rollsback' to 0, the default, when you rollback to the previous statement and is then increased to 1, so that when you hit the "o.value is [o.value]." part of the game, it's always 1). By NOT participating in rollback, o.value continues to increase. The first time you pass $ o.value += 1, it becomes 1. By rolling back without resetting that increase, and then progressing forward (and adding 1 again), you keep increasing the value. So it sounds like this is the opposite of what you want.

I'm also not sure how this system would work in practice. Rollback() would only rollback one statement. To tie that to a (presumably rare) currency seems kind of weird -- it seems to intuitively make more sense to rollback to the last meaningful choice or something of that nature.

As Remix said, I would think it makes more sense to jump to a previous point (say, a choice). Dealing with potential stat issues (by jumping, all python statements would be executed again as the game is not in rollback) could be dealt with a general on/off switch that could be triggered by pressing the button to consume the chronosoda. I mean, this is all a design question more than an implementation question, I think.

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: A NoRollback class question

#8 Post by trooper6 »

I think persistent values might do what you want Aviala? Though I think there still might be a problem with gaining chronosodas twice in the past. Though that could probably be done with persistent variables as well.
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], henne