[SOLVED] renpy.restart_interaction one click too late

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
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

[SOLVED] renpy.restart_interaction one click too late

#1 Post by Milkymalk »

I have a map that looks like this:
Image

The textbuttons on the right select a start and destination, and the screen calculates the route and displays it. It works, but with one problem: When I first click one of the buttons, nothing happens. When I click another button (or the same), the screen changes so it looks like it should BEFORE. Basically, the screen is always one button click behind.

This is how the buttons are declared (with a loop, of course):

Code: Select all

textbutton i.name action [SelectedIf(mapnach==i.name), SetVariable('mapnach', i.name), SetVariable('maproute', findroute(mapvon, mapnach)[0]), renpy.restart_interaction]
This button sets the new destination, forces the game to recalculate the route (not drawn yet, only getting the data), and then restart the interaction (i.e. the screen). The screen itself runs a loop to display the dots along the route.

It's as if the screen is redrawn before the changes take place, but I restart the interaction last in the action list for the buttons. So what am I doing wrong?
Last edited by Milkymalk on Wed Feb 28, 2018 11:24 am, edited 2 times in total.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: renpy.restart_interaction delays?

#2 Post by Ocelot »

You need to use an actual Action here. You cannot just pass a random function.Use Function screen action.
< < insert Rick Cook quote here > >

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: renpy.restart_interaction one click too late

#3 Post by Milkymalk »

Huh. I read in another thread to just use it like that (with emphasis on "without parentheses").

I changed it to Function(renpy.restart_interaction) instead, but no difference.

My newest guess is that I need to curry the findroute function, but I regularly give up when it comes to currying functions because I never seem to get it right.
Last edited by Milkymalk on Sun Feb 25, 2018 5:24 pm, edited 1 time in total.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: renpy.restart_interaction one click too late

#4 Post by Ocelot »

Do buttons lag behind too, or is it just the map?

Also, you should not even need restart_interaction: SetVariable restarts it itself.
< < insert Rick Cook quote here > >

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: renpy.restart_interaction one click too late

#5 Post by Milkymalk »

The buttons don't lag, if you mean their activated state.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: renpy.restart_interaction one click too late

#6 Post by Ocelot »

Your problem is in this: SetVariable('maproute', findroute(mapvon, mapnach)[0]). Remember: the whole reaso,n we need to write stuff like Function('foo', param1, param2) instead of foo(param1, param2), is because all screen code is executed when screen is shown. So we have to create objects, which defer actions to the moment, when you actually press the button, as opposed to executing everything when screen is shown.

Long story short, findroute(mapvon, mapnach)[0] will yield route from mapvon to mapnach according to values of variables as the were when screen was (re)shown.

I think it would be better to let map screen itself handle this:

Code: Select all

screen map():
    $ maproute = findroute(mapvon, mapnach)[0]
    # draw map
< < insert Rick Cook quote here > >

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: renpy.restart_interaction one click too late

#7 Post by Milkymalk »

You are right. I expected that much and tried around with currying the findroute function, but it seems that currying is just too complicated for me.

Thank you for your help!
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

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: renpy.restart_interaction one click too late

#8 Post by Remix »

You might also like to note that Function() will automatically cause a redraw due to the:
The Documentation wrote:This Action takes an optional _update_screens keyword argument, which defaults to true. When it is true, the interaction restarts and the screens are updated after the function returns.
So putting any call within a Function action *should* then redraw all the screens automatically.
Most, if not all, actions seem to do this anyway, just thought I would mention it.
Frameworks & Scriptlets:

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: renpy.restart_interaction one click too late

#9 Post by Milkymalk »

Thanks, good to know!
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: No registered users