r/RenPy • • 4h ago

Question Assistance with robo-barbie's chat_program code.

Hello - I'm having a huge headache with this one piece of code unfortunately and am either looking for pointers from people who have used it before OR anyone who might just have a clue as to what it is that's going wrong. ( I have looked for tutorials but have unfortunately come up empty: as I learn better through explainations and visuals/observation, hence why I've come forward here, ahaha. )

Firstly, the menu choice screen looks like this now, as outlined in robo-barbie's instructions:

screen choice(items, channel=active_window, chat_menu=True):
    style_prefix "choice"


    if chat_menu:
        # This is the choice menu for the chatroom. Style as you like
        frame:
            background None
            area (500, 100, 1369, 1640) #(851, 1129, 1349, 194)OLD
            if active_window == current_window:
                vbox:
                    xalign 0.0
                    spacing 0
                    yalign 0.5
                    for i in items:
                        textbutton i.caption:
                            if not i.kwargs.get("auto_send", True):
                                action i.action
                            else:
                                action [Function(chat_message, cn, i.caption, channel, is_player =True), i.action]
                            xmaximum 1300
                            background None
                            text_xalign 0.0


    else:
        # This is the choice menu for normal ADV mode. Style as you like
        vbox:
            xalign 0.5 yalign 0.5
            for i in items:
                textbutton i.caption action i.action:
                    xalign 0.5

Now I was able to get the screen to show up within the VN - there was some finangling to get all the text and the UI (a .png image) itself to show in the middle, text is all where it should be. ( Hence the #(851, 1129, 1349, 194)OLD comment, that's the original area.

In a seperate .rpy, called 'screens_chat.rpy' I sorted each section with labels to organise a little better.

label firstchat:
    $ reset_chats()
    scene comp1
    $ _rollback = True # disable rollback (robo public enemy #1)
    window hide # get rid of say screen
    show screen chat_messages_view # show chat screen (main function of the game)


    kiyo "Morning." (c= "#general", ot = cn)
    
    menu: 
        "gooooood morning, kiyoshi!":
            $ affinity += 1
            pass
        "hiiii kiyo~":
            $ affinity += 2
            pass
        "good morning!":
            pass   
    
    kiyo "Lock in."
    
    kiyo "Let's get some work done." (ot = cn)

The first label works fine, with the menus and such.

The SECOND label, I struggled with. I came up with the same error until I did some mucking about with the way I input the text. It DOES work now.
( It was specifically at the menu part: )

menu: 
        "are you okay?":
            cn "can't sleep?"
            kiyo "Nah. It's kinda… Difficult to."
            cn "..."
            cn "..."
            cn "are you texting me with your head out the window?"
            kiyo "So what if I am?"
            cn "you're going to make yourself sick smoking all the time."
            kiyo "Nah."
            cn "i did research on it."
            kiyo "Nah."
            cn "i'm being serious!"
            kiyo "Nah."
            $ affinity += 3
            $ renpy.pause()
            pass
        "why are you up so late?":
            kiyo "Can't sleep."
            cn "oh."
            cn "why?"
            kiyo "Dunno."
            cn "can I do anything?"
            kiyo "You're chatting to me."
            cn "oh."
            kiyo "Yeah."
            cn "well I don't sleep,"
            cn "so we can chat for as long as you like, kiyo."
            kiyo "Thanks, Cyph."
            $ affinity += 3
            $ renpy.pause()
            pass
    hide screen chat_messages_view

So that worked. And still works with label 3 written up, however with label 3; it ONLY allows me to pick the 'Ignore his message' option, otherwise the first one comes up with an error.

THE LABEL:

label chat3:
    $ reset_chats()
    scene comp1
    $ _rollback = True # disable rollback (robo public enemy #1)
    window hide # get rid of say screen
    show screen chat_messages_view # show chat screen (main function of the game)
    
    cn "kiyoooooooo?" (c = "Kiyoshi", ot = cn)


    menu: 
        "checking in."(c = "Kiyoshi"):
            kiyo "I'm doing bad." # should be the text response, but doesn't work.
            pass
        "{i}Don't message him.{/i}" (auto_send=False):
            pass
    $ reset_chats()


    cn "kiyo??"(c = "Kiyoshi")


    menu: 
        "checking in."(c = "Kiyoshi"):
            kiyo "Doing bad." # should be the text response, but doesn't work.
            $ renpy.pause()
        "{i}Don't message him.{/i}" (auto_send=False):
            kiyo "hhhhhhhhhhhhhhhhhhhhhhhhhhhh"(c = "#crashing_out")
            $ renpy.pause()
            $ kmurder += 1
            pass
    $ reset_chats()
    
    cn "kiyo...."(c = "Kiyoshi")


    menu: 
        "checking in??":
            kiyo "I'm doing bad."  # should be the text response, but doesn't work.
            $ affinity += 3
            $ renpy.pause()
            pass
        "{i}Don't message him.{/i}" (auto_send=False):
            kiyo "hhhhhhhhnnnnnnnn"(c = "#crashing_out")
            $ kmurder += 1
            $ renpy.pause()
            pass
    hide screen chat_messages_view
    jump firstchat #this was just to test if the rest of the code worked with this written up already; it does.

The error message:

[code]
I'm sorry, but an uncaught exception occurred. While running game code:
  File "game/screens_chat.rpy", line 257, in script
    menu:
  File "game/chat_program.rpy", line 234, in chat_message
    chat_pause(wait_time)
    ~~~~~~~~~~^^^^^^^^^^^
  File "game/chat_program.rpy", line 393, in chat_pause
    renpy.call_screen("fake_chat_pause", timer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Cannot start an interaction in the middle of an interaction, without creating a new context. -- Full Traceback ------------------------------------------------------------ Traceback (most recent call last):
  File "game/screens_chat.rpy", line 257, in script
    menu:
  File "renpy/ast.py", line 1825, in execute
    choice = renpy.exports.menu(choices, self.set, args, kwargs, item_arguments)
             ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/exports/menuexports.py", line 135, in menu
    rv = renpy.store.menu(new_items)
         ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "renpy/exports/menuexports.py", line 418, in display_menu
    rv = renpy.ui.interact(mouse="menu", type=type, roll_forward=roll_forward)
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/ui.py", line 306, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 2163, in interact
    repeat, rv = self.interact_core(
                 ~~~~~~~~~~~~~~~~~~^
        preloads=preloads,
        ^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "renpy/display/core.py", line 3263, in interact_core
    rv = root_widget.event(ev, x, y, 0)
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1281, in event
    rv = i.event(ev, x - xo, y - yo, cst)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1281, in event
    rv = i.event(ev, x - xo, y - yo, cst)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1281, in event
    rv = i.event(ev, x - xo, y - yo, cst)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/screen.py", line 805, in event
    rv = self.child.event(ev, x, y, st)
         ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1281, in event
    rv = i.event(ev, x - xo, y - yo, cst)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1510, in event
    rv = super(Window, self).event(ev, x, y, st)
         ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 273, in event
    rv = d.event(ev, x - xo, y - yo, st)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1281, in event
    rv = i.event(ev, x - xo, y - yo, cst)
         ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/behavior.py", line 1189, in event
    return handle_click(self.clicked)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "renpy/display/behavior.py", line 1111, in handle_click
    rv = run(action)
         ~~~^^^^^^^^
  File "renpy/display/behavior.py", line 404, in run
    new_rv = run(i, *args, **kwargs)
             ~~~^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/behavior.py", line 411, in run
    return action(*args, **kwargs)
           ~~~~~~^^^^^^^^^^^^^^^^^
  File "renpy/common/00action_other.rpy", line 618, in __call__
    rv = self.callable(*self.args, **self.kwargs)
         ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "game/chat_program.rpy", line 234, in chat_message
    chat_pause(wait_time)
    ~~~~~~~~~~^^^^^^^^^^^
  File "game/chat_program.rpy", line 393, in chat_pause
    renpy.call_screen("fake_chat_pause", timer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/exports/statementexports.py", line 341, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/ui.py", line 306, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 2129, in interact
    raise Exception(
        "Cannot start an interaction in the middle of an interaction, without creating a new context."
    )
Exception: Cannot start an interaction in the middle of an interaction, without creating a new context. 

Sorry for the long post - I genuinely cannot wrap my head around why the menus work sometimes and then don't work other times.

Perhaps it's a silly little issue I've missed - as I'm not the world's best coder, but if anyone can point me in the right direction I'd be exceptionally grateful.

TLDR: The menus work with this code sometimes, they don't work othertimes. Have I made a mistake?

2 Upvotes

2 comments sorted by

1

u/AutoModerator 4h ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/shyLachi 41m ago

That project has a demo. Did you try the demo? Does it run?

In the code you posted there is not "Ignore his message" option so either post the code which gives your the problem or tell us which choice is giving you the problem.