Custom menu doesn't update right after variable change

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
darxori
Newbie
Posts: 8
Joined: Tue Sep 17, 2019 8:21 pm
Projects: memoria-machina.com
Soundcloud: darxori
itch: darxori
Contact:

Custom menu doesn't update right after variable change

#1 Post by darxori »

Hello everyone! This is my first time posting here as I've been able to find the answers to most of my questions on these forums already but this one problem I can't quite figure out:

I've made a custom menu accessible from the main menu that shows a number of unlockable side stories and in game I am able to unlock each individual side story by doing something like this:

Code: Select all

menu:
        "A scenario appears"

        "Option A":
            "You unlocked a Side story!"
            $unlockSS(ss_1, True) #(sidestory variable name, unlock True or False)
            jump tests
    
        "Option B":
            "Lame, you didn't unlock anything..."
            jump tests
and that part seems to do what it's supposed to but my problem is when I go into the side story menu it only shows that the story is unlocked after I've opened that menu a second time

After I've unlocked Side story one and open the Side story menu the first time:
https://i.imgur.com/KZStlgc.png

After I open the Side story menu a second time:
https://i.imgur.com/GAc8klu.png

It's like the menu isn't refreshing right away and I'm not sure how to fix it

Here's my code for the menu:

Code: Select all

screen ss():

    tag menu
    add gui.main_menu_background

    textbutton ("<< MAIN MENU"):
         action ShowMenu("main_menu")
         xpos 100
         ypos 50
    fixed:

        vpgrid:
            cols 3
            yfill True
            ymaximum 800

            style_prefix "slot"

            xalign 0.5
            yalign 0.5
            spacing 200
            draggable True
            mousewheel True

            scrollbars "vertical"
            
            yinitial 0.0
            yspacing 230
            for i in ssList:
                button:

                    if i.unlocked == False:
                        action ShowMenu("ss")
                    else:
                        action Start(i.labelName)

                    has vbox

                    add i.thumbnail xalign 0.5 zoom 0.2


                    text i.title:
                        yoffset 15
                        xalign 0.5

                    text i.description:
                         xalign 0.5
                         ypos 30
                         yalign 0.0
                         style "slot_name_text"

            #I need these text lines so the viewport doesn't cut off some of the description of the last entries
            text ""
            text ""
            text ""


Any help would be appreciated

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Custom menu doesn't update right after variable change

#2 Post by isobellesophia »

Just to ask, why did you wrote this one?

Code: Select all

$unlockSS(ss_1, True)
it should be like this instead, sorry if this is only i know..

Code: Select all

$ persistent.unlockSS = True
Persistent can work and easy to write it, just replace your side story code with

Code: Select all

if persistent.unlockSS:
  ...
           else:
              ...
and try if it is works. Since i am very new anything about it..
I am a friendly user, please respect and have a good day.


Image

Image


darxori
Newbie
Posts: 8
Joined: Tue Sep 17, 2019 8:21 pm
Projects: memoria-machina.com
Soundcloud: darxori
itch: darxori
Contact:

Re: Custom menu doesn't update right after variable change

#3 Post by darxori »

oh the reason why I have it written like that is because I made a class for side stories (although I'm not entirely sure if it's written like it should be, it just works???) and a function to unlock them, they look like this:

Code: Select all

init python:

    class sideStory(object):
        def __init__(self, title = "Blank Side Story", ssNumber = 0, description = "", unlocked = False):
            self.title = title
            self.ssNumber = ssNumber
            self.unlocked = False
            self.labelName = "ss_0" + str(ssNumber)
            self.description = "Locked"
            self.thumbnail = "ss_locked.png"
            self.thumbnailDefault = "ss_" +str(self.ssNumber) + ".png"
            self.defaultDescription = description




    def unlockSS(ss,state = True):
        ss.unlocked = state
        if ss.unlocked == False:
            ss.thumbnail = "ss_locked.png"
            ss.description = "Locked"


        else:
            ss.thumbnail = ss.thumbnailDefault
            ss.description = ss.defaultDescription
            
# define your side stories ("Working title", id number, "description")
define ss_1 = sideStory("the first one", 1, "lame description")

So I'm not sure how persistent fits into this...

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Custom menu doesn't update right after variable change

#4 Post by RicharDann »

Try defining your side story objects with default instead of define. Also your ssList, I don't see it in the code you posted but I assume it contains all the side stories.

Code: Select all

# define your side stories ("Working title", id number, "description")
default ss_1 = sideStory("the first one", 1, "lame description")
default ssList = [ss_1] # Hypothetically this is the list you use in the screen 
define is generally used for objects whose properties won't generally change (like built-in Character); default should be used for variables or objects that are expected to change mid-game, like lists, and side stories in your case.

If that doesn't work, How are you showing the ss screen to the player, how can he/she access it so they can check if the story is updating properly?
The most important step is always the next one.

darxori
Newbie
Posts: 8
Joined: Tue Sep 17, 2019 8:21 pm
Projects: memoria-machina.com
Soundcloud: darxori
itch: darxori
Contact:

Re: Custom menu doesn't update right after variable change

#5 Post by darxori »

Oh yes the ssList was right under the other side stories i defined I just forgot to include the list in the reply

So I changed them all to defaults but now I seem to be running into a different problem, the Side story menu shows up properly when I access it by the button on a quickmenu I added in game for testing, but when I access the side story menu from the Main Menu they all show as locked

they both use the same action
in game menu:

Code: Select all

#added side menu
init:
    transform sideMenuZoom:
        zoom 0.15

screen side_menu_og(): #in game menu
    frame:
        xalign 1.0
        yalign 1.0
        xoffset 5
        yoffset 4
        has vbox:
            textbutton "ssMenu" action ShowMenu("ss") #sidestory menu
            imagebutton auto "gui/button/bag_%s.png" at sideMenuZoom action ShowMenu("inventoryMenu") 
            imagebutton auto "gui/button/book_%s.png" at sideMenuZoom action ShowMenu("bookMenu")
            imagebutton auto "gui/button/map_%s.png" at sideMenuZoom action ShowMenu("mapMenu")
Main starting menu:

Code: Select all

screen my_navigation():

    vbox:
        style_prefix "cbm"

        xalign 1.13
        yalign 0.5

        spacing gui.navigation_spacing

        textbutton _("Start New Game") action Start() style "cbm"
        textbutton _("Load Game") action ShowMenu("load") style "cbm"
        textbutton _("Side Stories") action ShowMenu("ss")   style "cbm" #side story menu
        textbutton _("Extras") action ShowMenu("extras") style "cbm"
        textbutton _("Options") action ShowMenu("preferences") style "cbm"
        textbutton _("Quit") action Quit(confirm=not main_menu) style "cbm"
Once the game is finished I was planning on having the player only be able to access the side story menu from the main start menu, I'm wondering if I need to do something with persistent data for it to show correctly in the main menu...

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Custom menu doesn't update right after variable change

#6 Post by isobellesophia »

you can do like this.

Before the label start

Code: Select all

default persistent.sideunlock = False
and when you unlock

Code: Select all

$ persistent.sideunlock = True
and then in screens.rpy

Code: Select all

if persistent.sideunlock:
  textbutton _("New side story") action Jump("label heere") style "cbm"
I am a friendly user, please respect and have a good day.


Image

Image


darxori
Newbie
Posts: 8
Joined: Tue Sep 17, 2019 8:21 pm
Projects: memoria-machina.com
Soundcloud: darxori
itch: darxori
Contact:

Re: Custom menu doesn't update right after variable change

#7 Post by darxori »

SO I THINK I FIGURED IT OUT! Since I had a class for my side stories I couldn't figure out how to use persistent directly inside of the class(because I think persistent is it's own class inside of renpy) but I managed to write something that makes a list of what state (true or false) each side story is in and I can store that list as persistent data, and I also managed to write a couple functions to either get or update the true or false state the side stories are in, which I needed to do in order for the menu to show properly outside of the game and even after closing the game

I have no idea whether I've just been making things unnecessarily more complicated by choosing to store my side stories this way but hey at least it seems to work


If anyone is curious or has any suggestions on how I can improve this here's my side story code (it's like 5am and I haven't slept yet so sorry if I wrote anything dumb or weird or unnecessary in there)

Code: Select all

init offset = -1

init python:
    if persistent.ssStates is None:
        persistent.ssStates = []

    class sideStory(object):
        def __init__(self, title = "Blank Side Story", ssNumber = 0, description = "", unlocked = False):
            self.title = title
            self.ssNumber = ssNumber
            self.unlocked = False
            self.labelName = "ss_0" + str(ssNumber)
            self.description = "Locked"
            self.thumbnail = "ss_locked.png"
            self.thumbnailDefault = "ss_" +str(self.ssNumber) + ".png"
            self.defaultDescription = description


    def update_ss_State():
        del persistent.ssStates[:]
        for i in ssList:
            persistent.ssStates.append(i.unlocked)

    def get_ss_State():
        for i in range(0, len(ssList)):
            ssList[i].unlocked = persistent.ssStates[i]

            if persistent.ssStates[i] == False:
                ssList[i].thumbnail = "ss_locked.png"
                ssList[i].description = "Locked"


            else:
                ssList[i].thumbnail = ssList[i].thumbnailDefault
                ssList[i].description = ssList[i].defaultDescription


    def unlockSS(ss,state = True):
        ss.unlocked = state
        update_ss_State()

        if persistent.ssStates[ss.ssNumber - 1] == False:

            ss.thumbnail = "ss_locked.png"
            ss.description = "Locked"


        else:
            ss.thumbnail = ss.thumbnailDefault
            ss.description = ss.defaultDescription

        #print persistent.ssStates



# define your side stories ("Working title", id number, "description")
default ss_1 = sideStory("the first one", 1, "lame description")
default ss_2 = sideStory("salad is bad unless it's a carb salad", 2, "oh damn")
default ss_3 = sideStory("Big cheese", 3, "this should be a description")
default ss_4 = sideStory("nut", 4, "another description")
default ss_5 = sideStory("oof", 5, "haha lmao")
default ss_6 = sideStory("buttrt", 6, "breakfast")
default ss_7 = sideStory("lmao", 7, "ah")

#List of Side Stories (using variable names)
default ssList = [ss_1,ss_2,ss_3,ss_4,ss_5,ss_6,ss_7]

label ss_01:

    show text "this is side story 1"
    scene bg sea
    "wooo hoo"
 # add your other side story labels below this
and then in your side story menu screen you'd need to have this in order for it to update correctly:

Code: Select all

screen ss():
    $get_ss_State()
    
    #then add the rest of your screen here

and if anyone wants to use any of my code for their own games feel free, (if you can make sense of it lol) but also beware I am not an expert and maybe some of this stuff might be buggy and awful i dunno yet

But thanks everyone for your help so far!

Post Reply

Who is online

Users browsing this forum: No registered users