Refresh Current Label/Return Previous Label

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
tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Refresh Current Label/Return Previous Label

#1 Post by tapanojum »

Hello.

I have a few image buttons that take you to different locations in the game. Depending on the time of day, a different screen will be called that shows a hotbutton (person) in that location.

So for example, in the Park at 12pm you see the hotbutton that lets you talk to Mark. At 1pm, a hotbutton appears that lets you talk to Stacy. I have a time function which acts like an in-game clock which is displayed on a separate screen at all times. So far so good.

Code: Select all

label Park:
    scene background
    if 12 <= TIMEVARIABLE < 13:
        call screen mark_button
    if 13 <= TIMEVARIABLE < 14:
        call screen stacy_button
I also have a button on a screen that allows me to fast forward time by 30 minutes. If I'm in the label at 12pm and see Mark, but decide I want to talk to Stacy instead, I can skip ahead 1 hour to have her appear. However if I do skip ahead, she will not appear. The only way to make it work is to click on the Park hotbutton again to 'refresh' the screen that shows the character hotbutton.

SKIP TIME BUTTON

Code: Select all

imagebutton: #+30 min
   xpos 75
   ypos -30
   focus_mask True
   auto "gui/icons/30m_icon_%s.png" hovered tt.Action("+ 30 mins") action(passtimecurry(30), Show("ui_text"))
passtimecurry is my in-game clock function.

I know how to call/hide a screen. I have dozens of these hotbutton screens for each character/situation so I'm not sure how to write a catch-all scenario. The game still works just fine, but it's an inconvenience I would like to fix. Is there a way to make the current label 'refresh'? Any ideas on where I should start?

Thank you once again.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Refresh Current Label/Return Previous Label

#2 Post by gas »

renpy.restart_interaction() should do the job.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: Refresh Current Label/Return Previous Label

#3 Post by tapanojum »

Thank you for the reply. I'm at work and can't test this yet. I should add renpy.restart_ interaction () to the action part of the fast forward buttom right?

Code: Select all

action(passtimecurry (30), Show ("ui_text"), renpy.restart_ interaction ())
Thank you!

Edit:
I tried the following code, but it freezes my game and requires a task manager termination.

Code: Select all

imagebutton: #+ 1 hour
        xpos 75
        ypos -30
        focus_mask True
        auto "gui/icons/1h_icon_%s.png" hovered tt.Action("+ 1 hour") action(passtimecurry(60), Show("ui_text"), renpy.restart_interaction())

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: Refresh Current Label/Return Previous Label

#4 Post by tapanojum »

After reading more about renpy.restart_interaction(), I tried adding the restart_interaction to the passtime() function that my screen button is calling.

Code: Select all

default passtimecurry = renpy.curry(pass_time)

init -1 python:

	def pass_time(mins=1):
	store.minn += mins
	renpy.restart_interaction()
This doesn't do anything though. Is it because I am using curry on passtime to use it on my screen?

UPDATE:

Found a post that has PyTom providing code on how to see the name of the current label. viewtopic.php?t=10578

Code: Select all

init python:
    def label_callback(name, abnormal):
        store.last_label = name

    config.label_callback = label_callback
So now my scene is successfully 'refreshed' every time I hit the +1h or +12h button.
So the variable last_label now holds the name of the label we are currently in. I've edited my code to be this.

Code: Select all

imagebutton: #+ 1 hour
        xpos 75
        ypos -30
        focus_mask True
        auto "gui/icons/1h_icon_%s.png" hovered tt.Action("+ 1 hour") action [passtimecurry(60), Jump(last_label)]
However there's now a new bug. Because the menu/load/save/preferences etc all have their own label in renpy, they are stored in the last_label variable. So if a user right clicks to pull up the menu and save their game, then immediately uses the + 1h/12h buttons, it will crash the game to the main menu. I'm guessing I need to run an if statement in the label_callback function to exclude the menu labels?

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: Refresh Current Label/Return Previous Label

#5 Post by tapanojum »

Anyone have an idea about this?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Refresh Current Label/Return Previous Label

#6 Post by Remix »

You should use any function inside a Function() call rather than alone. Function is a Ren'Py Action which helps control repeat calls during prediction

action [ Function( passtimecurry, 60), Show("ui_text"), Function( renpy.restart_interaction ) ]

I would also suggest just using Function( pass_time, 60 ) rather than currying it too. No need to curry as the Function action allows passing of args and kwargs anyway.
Frameworks & Scriptlets:

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: Refresh Current Label/Return Previous Label

#7 Post by tapanojum »

Thanks for the response, Remix!

I used curry because originally I was getting errors trying to use Function(), after seeing your example I see why. I wrote it as Function(pass_time(60)) instead of Function(pass_time, 60). So this part of the script now works correctly, however I'm now back to the original problem which is why I started using label_callbacks in the first place.

renpy.restart_interaction doesn't seem to actually be restarting the screen. Pass_time function correctly displays the proper amount of time being passed, but the characters entering and leaving the scene aren't shown unless I jump to another label first. Not sure what the issue is.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]