Force a screen to update/refresh?

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
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Force a screen to update/refresh?

#1 Post by qirien »

Hey, I have a little music player screen as part of my interface, and the buttons do what they are supposed to; however, the player text and buttons only update when another button is pressed somewhere else. I would like this screen to refresh itself often enough that when a new track is played, it will display the right track name, and when you stop or go to the next track, it displays the correct info.

It seems like clicking one of the imagebuttons should make the screen refresh (like if you click "Stop", it should no longer show the music that's playing and should display the play button instead), but that is not the case.

How can I make this screen refresh and show the correct information?

Code: Select all

init python:
    # Songs for computer pad
    pop_songs = MusicRoom(fadeout=0.5)
    pop_songs.add("music/Dandelion.ogg", always_unlocked = True)
    pop_songs.add("music/Shanghai_20_00.ogg", always_unlocked = True)
    pop_songs.add("music/Alpha.ogg", always_unlocked = True)
    pop_songs.add("music/YouUndone.ogg")

# Play music from the Music Room "pop_songs"
screen music_player():
    label "Music Player"
    $ current_song = renpy.music.get_playing()
    $ artist = ""
    $ song_title = ""
    if (current_song):
        if "Dandelion" in current_song:
            $ artist = "Kalabi"
            $ song_title = "Dandelion"
        #.... more setting song artists and titles deleted ....#

    if (current_song):
        text "{i}[song_title]{/i} by [artist]" size 14 ypos 30 xalign 0.5
    imagebutton auto "gui/previous_%s.png" xalign 0.3 yalign 1.0 action pop_songs.Previous()
    if (renpy.music.is_playing()):
        imagebutton auto "gui/pause_%s.png" xalign 0.5 yalign 1.0 action pop_songs.Stop()
    else:
        imagebutton auto "gui/play_%s.png" xalign 0.5 yalign 1.0 action pop_songs.Play()
    imagebutton auto "gui/next_%s.png" xalign 0.7 yalign 1.0 action pop_songs.Next()
Finished games:
Image
Image
Image

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

Re: Force a screen to update/refresh?

#2 Post by philat »

It's tough to say what you should do without knowing how you're using the screen, but renpy.restart_interaction() will refresh all screen elements.

User avatar
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: Force a screen to update/refresh?

#3 Post by qirien »

So, would I call that as part of a list of actions, like:

Code: Select all

    imagebutton auto "gui/previous_%s.png" xalign 0.3 yalign 1.0 action [ 
                pop_songs.Previous(), 
                renpy.restart_interaction()
                ]
When I try that, the whole Ren'py engine freezes up when it gets to that screen. I can't right-click or even quit; I have to kill the process. I looked at the documentation of renpy.restart_interaction, and it seems like what I probably need to use, but I'm not sure of how to call it properly.
Finished games:
Image
Image
Image

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Force a screen to update/refresh?

#4 Post by nyaatrap »

When you use functions as screen action, remove "()"

User avatar
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: Force a screen to update/refresh?

#5 Post by qirien »

:shock: Really?! Wow, you're right, thank you so much!
I guess it didn't come up as a syntax error because it is not parsed until the screen is shown.

Ohh, now I see it in the documentation. "Along with these actions, an action may be a function that does not take any arguments." Though it doesn't say that you need to remove the parentheses.
Finished games:
Image
Image
Image

Post Reply

Who is online

Users browsing this forum: No registered users