For every label, check if has been done or not. [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.
Post Reply
Message
Author
User avatar
sunwave
Regular
Posts: 45
Joined: Fri Apr 15, 2016 2:26 pm
Location: Netherlands
Contact:

For every label, check if has been done or not. [SOLVED]

#1 Post by sunwave » Sat May 28, 2016 8:53 pm

So, I have a game where you basically loop the same day over and over again. There are many choices that can make you do different things, but the main gameplay element is that you learn something from each loop, which allows you NEW choices in the next loop. Now, I've got this pretty much figured out, like "knowing a code so you can use the secret door next time" or "I know what to say to make people trust me" or "I know we're about to be attacked" and stuff like that.
You will always die at the end of a loop, but as long as you learned something new or got some new interactions, it's useful. If you get a bad end, you probably learned nothing. I want the player to actually be penalized for getting bad ends by
1) Having the player character get depressed if he dies too often without learning anything (this will affect dialogue and in extreme cases even prevents certain scenes).
2) Having the player character give up on escaping the loop if he is too depressed (Just some scenes to make the player feel bad, and then they can restart the last loop with OK-ish mood).

So he gets his mood down by messing up. And he gets his mood up by:
1) Experiencing a scene that has not been experienced before.
2) Learning new information.

So, the 'noob' way of doing this is like so:

Code: Select all

label start:
    if not persistent.var_mood >= 0:
        $ persistent.var_mood = 10
    if persistent.var_mood == 0:
        "You give up trying to fix the loop."
        "(in more text)"
        return

label scene_01:
    if not persistent.scene_01_done == 1:
        $ persistent.var_mood += 1
        $ persistent.scene_01_done = 1
    "Some stuff happens."
    "To next scene"

label scene_02:
    if not persistent.scene_02_done == 1:
        $ persistent.var_mood += 1
        $ persistent.scene_02_done = 1
    "Some stuff happens."
    menu:
        "Do something good":
            jump scene_03_good
        "Do something bad":
            jump scene_03_bad
        "Use the code." if persistent.info_01 == 1
            jump scene_04

label scene_03_good:
    if not persistent.scene_03_done == 1:
        $ persistent.var_mood += 1
        $ persistent.scene_03_done = 1
    "Scene happens."
    "More scene happens."
    "You learn something new!"
    if not persistent.info_01 == 1
        $ persistent.info_01 = 1
        $ persistent.var_mood += 3
    "Whoops, you died anyway. At least it wasn't for nothing."

label scene_03_bad:
    "You fail to learn anything new. You died for nothing. Sad panda."
    $ persistent.var_mood -= 4
    if persistent.var_mood <= 0:
        $ persistent.var_mood == 0

label scene_04
    "etc."
Obviously, this creates a TON of variables and I feel there is a better way. I'm okay with being a noob, but I'm not okay with failing to learn anything at all, so I'm asking this:
IS there a more efficient way? If not, is there a way to make the variables connect to the label they're under? So I can turn this...

Code: Select all

    if not persistent.scene_03_done == 1:
        $ persistent.var_mood += 3
        $ persistent.scene_03_done = 1
...into something 'general' that I can copy-paste to all labels without needing to manually change the numbers/names for each label?

BONUS QUESTION:
Can the below code be replaced with "default persistent.var_mood = 10"? I'm not 100% sure what "default" really does.

Code: Select all

    if not persistent.var_mood >= 0:
        $ persistent.var_mood = 10
Last edited by sunwave on Mon May 30, 2016 7:13 am, edited 1 time in total.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: For every label, check if has been done or not.

#2 Post by xavimat » Sun May 29, 2016 4:36 pm

1. Check these two functions:
https://www.renpy.org/doc/html/other.html#renpy.is_seen
https://www.renpy.org/doc/html/label.ht ... seen_label

2. Why all those "persistent" variables?
You know that "persistent" values will be there when the player quits the game and restarts it. So there will be never a second "fresh start" of the game.
You can use a simple variable "var_mood".

3. Some of your "if" statements are illogical.
For example, your "label start" first checks "if not persistent.var_mood >= 0:"
If, say, the value == 0, changes it to 10: $ persistent.var_mood = 10
And then checks if it's 0 and does other things. But it will never be 0, because, if it were 0, the line before would have changed it to 10.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
sunwave
Regular
Posts: 45
Joined: Fri Apr 15, 2016 2:26 pm
Location: Netherlands
Contact:

Re: For every label, check if has been done or not.

#3 Post by sunwave » Sun May 29, 2016 7:47 pm

1) Thank you. I will try experimenting with those. EDIT: the "renpy.is_seen" is exactly what I was looking for. Especially since it's a self-referencing function and it doesn't need a name. Handy enough to put anywhere in the script (even at non-label locations).

2) Yes, I know there will never be a fresh game. You are supposed to restart the game with intact memories from previous runs (you can't even win the first few times). There is a "forget memories" button in the main menu for if you really want to restart. So everything relating to the main character is persistent and all things related to other characters are not persistent. The main character mood carries over, and the information you learned also carries over. Relationships/things you said/actions you took, that affect other characters, will not carry over (since I didn't make those persistent).
I know I could just go back to "label start" instead of allowing the "new game" option, but then people might get confused by the difference between "new game" and "from start after getting an ending", so I decided to make just a ton of persistent variables.

3) Actually, you're wrong.

Code: Select all

if not persistent.var_mood >= 0:
Will not trigger if var_mood is zero or higher, so basically only the first time (since it starts at "None" becoming "10", and after that the lowest it can go is zero itself).

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: For every label, check if has been done or not.

#4 Post by xavimat » Mon May 30, 2016 5:08 am

sunwave wrote:3) Actually, you're wrong.

Code: Select all

if not persistent.var_mood >= 0:
Will not trigger if var_mood is zero or higher, so basically only the first time (since it starts at "None" becoming "10", and after that the lowest it can go is zero itself).
Right. My bad.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
sunwave
Regular
Posts: 45
Joined: Fri Apr 15, 2016 2:26 pm
Location: Netherlands
Contact:

Re: For every label, check if has been done or not.

#5 Post by sunwave » Mon May 30, 2016 7:13 am

Well, thank you anyway. Marking as solved.

Post Reply

Who is online

Users browsing this forum: Google [Bot]