Ren'Py "renpy.invoke_in_new_context()"... doesn't invoke new context [call renpy.input from menu]

Khelben

New Member
Dec 8, 2018
5
0
1688405332611.png

So, I've built a custom Journal Screen for the VN I'm working on. And the screen is displaying everything perfectly. Journals are a custom python class that stores text and image references and some metadata, and there are some methods and whatnot. Anyways. All of it works but one thing I can't figure out, and I've had no luck finding a sensible answer via google. I'm trying to make it so that when you click the Journal title at the top of the sheet of parchment (the date in the gothic font), it allows the player to re-title the journal.

So it's a textbutton

Code:
textbutton journal.title action Function(journal.input_title) text_style "journal_title"
And it calls a function in the Journal class which should be invoking an input window in a new context.

Code:
        def input_title(self):
            temp = None
            temp = renpy.invoke_in_new_context(renpy.input("Enter a new title for the journal.", default = self.get_title(), length=32)).strip()
            if temp:
                self.set_title(temp)
But for reasons I've been unable to figure out, "invoke_in_new_context" is not invoking in new context, and I keep getting the same error.

Code:
Exception: Cannot start an interaction in the middle of an interaction, without creating a new context.
How do I get the temp = renpy.invoke_in_new_context(renpy.input("Enter a new title for the journal.", default = self.get_title(), length=32)).strip() line to run in a new context so I can open the input from inside the Journal menu screen?

Or - is there perhaps a better way to handle renaming the data?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,143
14,828
And it calls a function in the Journal class which should be invoking an input window in a new context.
While still being punctually interesting, all functions creating a new context are totally outdated nowadays. 95% of the time there's a better way to proceed, that don't need to change the context. In the present case, Showing a custom input screen, defined as modal, would have better result.


But anyway, there's absolutely no need for an input windows for what you want to do.

/!\ wrote on the fly /!\
Python:
default journalName = "Journals"

screen whatever():

    [...]

    button:
        key_events True
        action VariableInputValue( "journalName" ).Toggle()

        input:
            value VariableInputValue('journalName')

    [...]
Normally this should be enough, showing the title, and letting the player edit it when clicking on it. Exactly like the page label for the save/load screen.



As for the reason of the error you get, it's because your code is broken.

Code:
temp = renpy.invoke_in_new_context(renpy.input("Enter a new title for the journal.", default = self.get_title(), length=32)).strip()
expect a callable as first argument, you're passing it a function return value. What explain the error you get, since renpy.input is processed before renpy.invoke_in_new_context ; therefore processed in the current context.

The correct syntax should be renpy.invoke_in_new_context( renpy.input, "Enter a new title for the journal", default=self.get_title(), lenght=32 ).strip().
 
  • Like
Reactions: Khelben

Khelben

New Member
Dec 8, 2018
5
0
That makes a lot more sense.

I don't know why, but I somehow didn't realize it was taking the function name as the first argument and then all the arguments as other arguments after that - I guess it's been a long day. I do have some work experience with programming some business and web software, but this is my first project using Ren'py or Python, so I find myself trying to find documentation on how to do stuff a lot, and sometimes I realize I've made a pretty stupid mistake, or occasionally I just can't find the functionality I'm looking for.

You're right, seeing how input actually works in this case, input is far from ideal. I was expecting a textbox modal of some kind styled similar to choices to pop up, not a prompt in the dialogue box. I'll have to try your other approach when I get up.

Thanks!