[solved] Problem with nested interactions

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
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

[solved] Problem with nested interactions

#1 Post by Ayutac » Sun Jan 06, 2013 8:35 am

Ayutac wrote:[method in screen problem]

EDIT: Today on the 6.1.'13 was the first time I found a topic of mine with search function and it helped me solving the problem. Prosit!
Until the point I encountered another one in this very context.
So, I'm calling an inventory screen by clicking on a button of the quickmenu, wich is itself within the say screen.

Code: Select all

screen quickmenu
    [...]
        if location == 0:
            textbutton _("Inventory") action ShowMenu('inventory')
Then I click on the Pokeball to get my action.

Code: Select all

screen inventory
    tag menu
    [...]
                        imagebutton:
                            idle "item01.png"
                            hover "item01_selected.png"
                            action [SetVariable("item", i), useItem, Return]
                            hovered SetVariable("mouseOverItem", i)

Code: Select all

    python:
        def useItem():
            global item
            if girl != -1 or inventory[item].hasWith() != True:
                return
            if inventory[item] == [...]
                [...]
            else:
                Oak("[prota.Name], this isn't the right time for this.")
                Prota("Professor?")
From the linked topic I know that putting methods in screens like that isn't a nice thing to do, but that's not even the issue. I'm getting this:

Code: Select all

While running game code:
  File "game/itemDB.rpy", line 124, in python
Exception: Cannot start an interaction in the middle of an interaction, without creating a new context.
I can't even be mad, 'cause I have a clue why it doesn't work. I'm in the middle of dialog, call a menu (which is supposed to go back to the dialog), and then I want to call dialog again, even choices. Not nice.

Details:
The basic idea is that the player should have access to his inventory everytime. (If I wouldn't want that, I could just add the inventory as a navigation point.) Maybe it is not so nice to search things in your bag when someone is talking to you, but doing that when giving a choice isn't very different. An alternative would be to make the inventory accessable only on navigational points since they are all labeled and can easily be jumped to. But then I would either have to add the menuitem everywhere, what I don't want, or I have to show the button in the quickmenu only when the player is at such navigational point and I don't know how to do that (since choice appear out of navigational points too).
So basically, how do I create new content and be sure to (automatically) jump back to the old one after I'm finished
Last edited by Ayutac on Sun Jan 06, 2013 1:15 pm, edited 1 time in total.
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

Kinsman
Regular
Posts: 130
Joined: Sun Jul 26, 2009 7:07 pm
Location: Fredericton, NB, Canada
Contact:

Re: Problem with nested interactions

#2 Post by Kinsman » Sun Jan 06, 2013 12:12 pm

It looks like the issue is where you have Oak and Prota talking with each other.

An "interaction" in Renpy is the loop where the user clicks on something, reads the result, and then has another opportunity to click on something.

Menus count as interactions, but so do basic things like clicking on the screen to go to the next say statement. When Oak and Prota start talking inside useItem, that's the new interaction that you're trying to do, inside of the menu interaction.

There is a statement, renpy.call(label) that terminates the current Renpy statement (or the python block you're in the middle of) and goes to the label. You could use that, like you're using renpy.jump elsewhere, to move to any inventory-related conversations Oak and Prota might have.

According to the documentation, when renpy.call returns, "control will be passed to the statement following the current statement". Since we clicked a menu button to make renpy.call happen, I don't know if the "statement following the current statement" would be in the main script or not. You'll have to experiment.

Also, check http://lemmasoft.renai.us/forums/viewto ... =8&t=18606 to read about a bug that renpy.call has at the moment.
Flash To Ren'Py Exporter
See the Cookbook thread

Kinsman
Regular
Posts: 130
Joined: Sun Jul 26, 2009 7:07 pm
Location: Fredericton, NB, Canada
Contact:

Re: Problem with nested interactions

#3 Post by Kinsman » Sun Jan 06, 2013 12:26 pm

OK, I think I've got it figured out. Taking actions at any time! What fun..

Code: Select all

init:
    python:
        def caat_function():
            renpy.call("poem")
            return

screen call_at_any_time_test:
    textbutton "Poem" action caat_function xalign 0.1 yalign 0.1

label start:
    show screen call_at_any_time_test
    "See that poem button in the upper left?"
    "Press it whenever you want, and I'll stop talking and give you a poem instead."
    "And when I'm done the poem, I'll go back here and continue with the next line."
    "Only two lines left, you better press that poem button now if you haven't yet."
    "All done."
    return
    
label poem(**kwargs):
    # The (**kwargs) bit is a workaround for a Renpy bug with renpy.call()
    hide screen call_at_any_time_test
    "The gentle journey jars to stop."
    "The drifting dream is done."
    "The long gone goblins loom ahead."
    "The deadly, that we thought were dead,"
    "Stand waiting, every one."
    return

EDIT: I notice that if you press the Poem button while you're at a menu, when you return, the script will act as if you picked the last menu option.

That isn't what you want, if the player is allowed to click an inventory button while being shown a menu. There are two steps to solving the menu problem:

1. Use renpy.display_menu to show your menu, and test the result variable instead of using the Renpy menu statement.

2. Put the menu in a while loop, so that if the player skips the menu statement after pressing an inventory button, the while loop will force the player back into dealing with the menu..

Code: Select all

    "This is a different way to show a menu, but it's safe against pressing the Poem button."
    $result = -1
    while result == -1:
        $result = renpy.display_menu([("Option a",0), ("Option B",1), ("Option C",2)])
        if result == 0:
            "You chose Option a."
        elif result == 1:
            "You chose Option b."
        elif result == 2:
            "You chose Option c."
    "And now, the menu is complete."
Last edited by Kinsman on Sun Jan 06, 2013 12:49 pm, edited 1 time in total.
Flash To Ren'Py Exporter
See the Cookbook thread

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: Problem with nested interactions

#4 Post by Ayutac » Sun Jan 06, 2013 12:41 pm

That looks like it would work. Just one question: Why don't you get this:

Code: Select all

File "game/itemDB.rpy", line 133: 'return' outside function
so, I would be fine putting everything into the function, just deactivating the screen, but then I still get the error.
Newest try was this one:

Code: Select all

python:
        def useItem():
            global item
            renpy.hide_screen('inventory')
            [...]
EDIT: Your example worked. Wait, what? Give me a minute.
EDIT: Make that 5 Minutes.
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

Kinsman
Regular
Posts: 130
Joined: Sun Jul 26, 2009 7:07 pm
Location: Fredericton, NB, Canada
Contact:

Re: Problem with nested interactions

#5 Post by Kinsman » Sun Jan 06, 2013 12:54 pm

I edited my previous post, make sure you read what I said about menus.

Anyway, hang in there. It looks like for your first project you wanted to do something different from most visual novels. Ren'py is flexible enough to help you, but it does require some extra work.
Flash To Ren'Py Exporter
See the Cookbook thread

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: Problem with nested interactions

#6 Post by Ayutac » Sun Jan 06, 2013 1:14 pm

Kinsman wrote:EDIT: I notice that if you press the Poem button while you're at a menu, when you return, the script will act as if you picked the last menu option.
Objection! My script doesn't behave this way.

Mine confusion before had two causes. First I wasn't aware that Ren'Py and Python handle the 'return' statement in different ways. Second I tried not to use the caat_function, but that didn't worked well.
It looks like for your first project you wanted to do something different from most visual novels. Ren'py is flexible enough to help you, but it does require some extra work.
A little misunderstanding. I haven't chosen Ren'Py and then thought of a nice first project. I chose the project and found out Ren'Py would be ideal to create it. So I learned Python and Ren'Py, coming from Java. Now I only have to struggle a bit with screen language instead of despairing of C-Subrotines to get the images rendered properly. (Ironically, I still have the rendering problem, but it seems to be a hardware problem since I can't take screenshots of it.)

Nevertheless, your Edit with the while loop is the simple solution to that other problem: how to easy up the navigation and spare some jumps.

Kinsman, thank you very much and from my opinion you are the most helpful user today :D
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_