I have a problem with refreshing an array on a screen

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
MrDracosaurio
Newbie
Posts: 3
Joined: Fri Apr 03, 2020 12:21 pm
Contact:

I have a problem with refreshing an array on a screen

#1 Post by MrDracosaurio »

Hello, I am trying to display text that changes based on a time variable and an array.

After various tests, the variable and the array seem to work. The variable changes from 0 to 1 when I use the button, and the array displays morning, afternoon, and evening if I manually put in the numbers 0, 1 or 2. But, if I use "time_day"[timevar]" it doesn't refresh, it always stays in the morning(if I manually change the timevar to start at 1 it displays the afternoon).

This is the array and variables of the time and the script to change it.

Code: Select all

define timevar = 0  ## These are time of the day - 1 = Morning, 2 = Afternoon, 3 = Evening
define time_day = ["Morning","Afternoon","Evening"]

################################################################################
# SCRIPT
################################################################################

label time_change:
    if timevar == 2: #This change the day
            $ timevar = 0

    else:
        $timevar +=1
This is de map screen

Code: Select all

screen map_screen():

    add "map.png" # This is the town map image
    modal True # Clicking won't advance the dialogue

    vbox:
        xpos 14
        ypos 17

        vbox:

            text time_day[timevar] #This doesn't update when timevar changes it
            text "[timevar]" #This does change when I click the button
            text [time_day[1]] #This displays afternoon but if I change it it can display everything

    hbox:
        xalign 0.99
        ypos 5
    if timevar == 0:
        imagebutton auto "gui/map/store_%s.png" action [Jump("shop_prologue")] xpos 679 ypos 170 #This is the button that changes the time on the next code
This is only to test the time change label and it works

Code: Select all

label start:

    $ map_return = "start"

    call screen map_screen
    with fade

    window hide
    pause

label shop_prologue:

    $ map_return = "shop_prologue"

    call time_change
    "Hi"
    jump start

    return
I've been working with this for quite a few days, a few days ago it worked, but it has stopped working and we don't know why. Thank you very much in advance.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: I have a problem with refreshing an array on a screen

#2 Post by rayminator »

this is what I have and it works try something like this it might give you a idea why yours is not working maybe

Code: Select all

default daytime = 0

Code: Select all

if daytime == 0:
            $ dd = _("Morning")
        elif daytime == 1:
            $ dd = _("Afternoon")
        elif daytime == 2:
            $ dd = _("Evening")
        elif daytime == 3:
            $ dd = _("Night")        

        text "[dd]":
            size 30
            color "#0099cc"
            outlines [(3, "#000000", 0, 0)]
            font "font/foo_regular.ttf"

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: I have a problem with refreshing an array on a screen

#3 Post by zmook »

I think how this works is, Renpy calculates the text string when the screen is shown, and so if timevar=0 at that point, your three consecutive texts are stored as:

Code: Select all

            text "Morning"  # = time_day[0] 
            text "[timevar]" #This does change when I click the button
            text "Afternoon"  # = [time_day[1]]
Note the trick: renpy saves the middle one with a placeholder in the text, and *that* is re-evaluated every time the screen is redrawn. The other thing to know is that any python statements in the screen are also re-evaluated every time. So the trick is that any value that you want to update while a screen is showing, should be calculated in the screen and interpolated into text.

Code: Select all

       $ time_label = time_day[timevar]
       text "[time_label]"
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

MrDracosaurio
Newbie
Posts: 3
Joined: Fri Apr 03, 2020 12:21 pm
Contact:

Re: I have a problem with refreshing an array on a screen

#4 Post by MrDracosaurio »

zmook wrote: Thu Dec 16, 2021 5:41 pm I think how this works is, Renpy calculates the text string when the screen is shown, and so if timevar=0 at that point, your three consecutive texts are stored as:

Code: Select all

            text "Morning"  # = time_day[0] 
            text "[timevar]" #This does change when I click the button
            text "Afternoon"  # = [time_day[1]]
Note the trick: renpy saves the middle one with a placeholder in the text, and *that* is re-evaluated every time the screen is redrawn. The other thing to know is that any python statements in the screen are also re-evaluated every time. So the trick is that any value that you want to update while a screen is showing, should be calculated in the screen and interpolated into text.

Code: Select all

       $ time_label = time_day[timevar]
       text "[time_label]"
Sorry to respond so late. I tried to do as you said and it worked, thank you very much for the help. I've been trying to do this for a long time with this without being able to move forward.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]