[SOLVED] Monitoring persistent values / code not functioning

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
famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

[SOLVED] Monitoring persistent values / code not functioning

#1 Post by famakki1 »

Hi all,

I am having an issue with some persistent values and was wondering if there is a way to monitor them live while the game is running for testing?

Specifically I am having trouble accomplishing this:

Code: Select all


    if persistent.truecheck == "True":
        $ persistent.ending == "ch2truejmp"
    else:
        $ persistent.ending == "ch2jmp"

This code is placed at the end of chapter 1, and is meant to change the main menu as shown in codes below.
The above code, persistent.truecheck is a flag set to True at the end of the game. Depending on that, the value of $ persistent.ending will be set.

Code: Select all


screen main_menu:

    tag menu

    if persistent.ending == "ch2jmp":
        use ch2jmp
    elif persistent.ending == "ch2truejmp":
        use ch2truejmp
    if persistent.ending == "ch3jmp":
        use ch3jmp
    elif persistent.ending == "ch3truejmp":
        use ch3truejmp
    if persistent.ending == "ch4jmp":
        use ch4jmp
    elif persistent.ending == "ch4truejmp":
        use ch4truejmp
    if persistent.ending == "titletrue":
        use titletrue
    elif persistent.ending == "title":
        use title
    else:
        use title

I have different main menu for different situations. The background image changes if the user has reached the true end. The other ch(X)jmp screeens are the same except the game returns to the main menu with a new button allowing jumping to next chapter.

Code: Select all


screen ch2jmp:
    tag menu

    imagemap:
        ground "data/main_menu/Title_NC_Idle.png"
        idle "data/main_menu/Title_NC_Idle.png"
        hover "data/main_menu/Title_NC_Hover.png"
    
        hotspot(474,364,332,42) action Start("chapter2")
        hotspot(466,476,340,40) action ShowMenu("load")
        hotspot(470,532,346,40) action ShowMenu("preferences")
        hotspot(474,586,316,40) action ShowMenu("extras")
        hotspot(486,642,310,38) action Quit()

screen title:
    tag menu

    imagemap:
        ground "data/main_menu/Title_Idle.png"
        idle "data/main_menu/Title_Idle.png"
        hover "data/main_menu/Title_Hover.png"

        hotspot(466,422,334,36) action Start()
        hotspot(466,476,340,40) action ShowMenu("load")
        hotspot(470,532,346,40) action ShowMenu("preferences")
        hotspot(474,586,316,40) action ShowMenu("extras")
        hotspot(486,642,310,38) action Quit()

The code is correct as the game runs, so am I going about this the wrong way? As shown above, the first hotspot is meant to jump to label called chapter2 but instead the game returns to the menu title.
Last edited by famakki1 on Thu Apr 06, 2017 9:00 am, edited 1 time in total.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Monitoring persistent values / code not functioning

#2 Post by indoneko »

famakki1 wrote:I am having an issue with some persistent values and was wondering if there is a way to monitor them live while the game is running for testing?
How about using an overlay screen that display the value of your persistent variable?
Specifically I am having trouble accomplishing this:

Code: Select all

    if persistent.truecheck == "True":
        $ persistent.ending == "ch2truejmp"
    else:
        $ persistent.ending == "ch2jmp"
How about something like this? (assuming that you check True as Boolean instead of string)

Code: Select all

    if persistent.truecheck:
        $ persistent.ending = "ch2truejmp"
    else:
        $ persistent.ending = "ch2jmp"
My avatar is courtesy of Mellanthe

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Monitoring persistent values / code not functioning

#3 Post by famakki1 »

Hi indoneko,

While I was testing I tried your format as well, and did so again, however it doesn't seem to work...

Despite it being set to ch2jmp/ch2jmptrue in the code, the main menu still remains title. :(

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Monitoring persistent values / code not functioning

#4 Post by indoneko »

Try deleting all persistent first before launching your game. And the the save files too.
If it still failed, can you attach a trimmed version of your project to replicate the issue?
My avatar is courtesy of Mellanthe

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Monitoring persistent values / code not functioning

#5 Post by famakki1 »

Hi indoneko,

here is a project replicating the issue.

The main menu is literally a huge button so don't worry too much of it, since this is just a demo mockup. You will notice, the menu will not change to chjmp, and instead it will loop back to default title screen...
Attachments
persistent-error.zip
(303.2 KiB) Downloaded 16 times

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Monitoring persistent values / code not functioning

#6 Post by indoneko »

OK, try adding a line of dialogue right after you set the persistent variable value... like this :

Code: Select all

    if persistent.truecheck:
        $ persistent.ending = "ch2truejmp"
    else:
        $ persistent.ending = "ch2jmp"
    "..." # ---> additional line of dialogue. 
    return
My avatar is courtesy of Mellanthe

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Monitoring persistent values / code not functioning

#7 Post by famakki1 »

Doesn't seem to affect anything. I even tried 'forcing' it by changing the code in the demo to:

Code: Select all

    "Chapter ends here"
    
    #if persistent.truecheck:
    #    $ persistent.ending = "ch2truejmp"
    #else:
    #    $ persistent.ending = "ch2jmp"
    
    if persistent.truecheck:
        jump p1
        
    if not persistent.truecheck:
        jump p2
    
label p1:
    
    $ persistent.ending = "ch2truejmp"
    
    "To jump to next chapter, menu should change to chjmp because of statements, chjumptrue should'nt work since user has not finished the game"
    jump r1
label p2:
    
    $ persistent.ending = "ch2jmp"
    
    "To jump to next chapter, menu should change to chjmp because of statements, chjumptrue should'nt work since user has not finished the game"
    jump r1

label r1:
    
    "..."
    
    return
Even this doesn't help. Weird.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Monitoring persistent values / code not functioning

#8 Post by indoneko »

After a more thorough checking, I find out that your conditional for main menu screen is flawed.

Code: Select all

screen main_menu:
    tag menu

    if persistent.ending == "chjmp":
        use chjmp
    elif persistent.ending == "chjmptrue":
        use chjmptrue
    if persistent.ending == "titletrue":
        use titletrue
    else:
        use title
For example, the chapter jump screen true route (chjmptrue) will never be used because you don't give access to the player to replay chapter 1, and you don't set the persistent.ending value to "chjmptrue" in chapter 2.

If you're curious about the persistent value, how about adding an overlay to display the value of your persistent variable? Something like this :

Code: Select all

init:    
    python hide:
    # # This is an overlay for displaying the persistent variable's value
        def tracker_overlay():              
            if persistent.ending:
                ui.text("Ending = "+persistent.ending,
                        xpos=0.05, xanchor="left",
                        ypos=0.05, yanchor="top")
            else:
                ui.text("Ending = None",
                        xpos=0.05, xanchor="left",
                        ypos=0.05, yanchor="top")
            if persistent.truecheck:
                ui.text("Truecheck = "+str(persistent.truecheck),
                        xpos=0.05, xanchor="left",
                        ypos=0.1, yanchor="top")
            else:
                ui.text("Truecheck = None",
                        xpos=0.05, xanchor="left",
                        ypos=0.1, yanchor="top")
        config.overlay_functions.append(tracker_overlay)

label start:

    "At the game start, the persistent variable's value is None"    
    "So, for now it should be normal main menu."

    "Chapter ends here"
    
    "To jump to next chapter, menu should change to chjmp because of statements, chjumptrue should'nt work since user has not finished the game"
    
    if persistent.truecheck:
        $ persistent.ending = "ch2truejmp"  # ---> this line will never be reached!!!
    else:
        $ persistent.ending = "ch2jmp"

    pause(.1)   # you can also use this short delay instead of text

        
    return
    
    
label chapter2:
    
    "Now chapter 2"
    "Now game is ending"
        
    $ persistent.truecheck = True
    pause(.1)

    return 
You might also want modify your screen so that you can display your persistent variable's value.

Edit : if you can't fix this problem yourself, just PM me the full project (without the build). I will try to clean it up for you.
My avatar is courtesy of Mellanthe

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Monitoring persistent values / code not functioning

#9 Post by famakki1 »

Hi indoneko,

Thanks for your help so far, Ill try out using the persistent monitor and see if I can play around the code a bit.

Regarding the project, it is a bit flawed for the demo, but in the project I am working on, there are 4 chapters, and 3 next chapter screens with 2 variants. The first variant is for if the user hasn't finished the game, and the second is if he/she has. Now regarding preventing replay of chapter 1, in the chapter jump screens there are 2 options: Next Chapter and Start, so the user can restart. Furthermore, the jump screens will immediately be replaced again by menu screens after the user clicks on next chapter.

Flowchart of what I am actually trying >

First playthrough > Default title screen
End of chapter 1 > Default title screen with new button called Next Chapter, to allow user to jump to label chapter2. After jumping menu set back to default varient 1.
End of chapter 2 > Default title screen with new button called Next Chapter, to allow user to jump to label chapter3. After jumping menu set back to default varient 1.
End of chapter 3 > Default title screen with new button called Next Chapter, to allow user to jump to label chapter4. After jumping menu set back to default varient 1.
End of chapter 4 > Separate persistent variable to know the game has been completed once. Main menu varient 2 is now true forever and repeat above.

EDIT: Now I think about I might not actually need to use if/else, I could just jump directly to the screens... let me try doing that and I'll get back here with results.

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Monitoring persistent values / code not functioning

#10 Post by famakki1 »

Hi indoneko,

I feel really embarrassed right now... :oops:

I found the issue, thanks to using your script I was able to confirm that my persistent values are working as expected. The problem was that no matter what, the menu wasn't changing... and hence there laid the problem...

Code: Select all

screen main_menu:

    tag menu

    if persistent.ending == "ch2jmp":
        use ch2jmp
    elif persistent.ending == "ch2truejmp":
        use ch2truejmp
    if persistent.ending == "ch3jmp":
        use ch3jmp
    elif persistent.ending == "ch3truejmp":
        use ch3truejmp
    if persistent.ending == "ch4jmp":
        use ch4jmp
    elif persistent.ending == "ch4truejmp":
        use ch4truejmp
    if persistent.ending == "titletrue":
        use titletrue
    elif persistent.ending == "title":
        use title
    else:
        use title
Instead of if > elif > elif ... else, for some reason (most like copy and paste since I made code on Notepad then moved it to Jedit) my code is if > elif >if > elif ... else.... No wonder it doesn't work!

Sorry for bothering you but thanks for your help ! 8)

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: [SOLVED] Monitoring persistent values / code not functio

#11 Post by indoneko »

Hahaha... yeah, no problem~ :D
My avatar is courtesy of Mellanthe

Post Reply

Who is online

Users browsing this forum: No registered users