Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Controller Support Expansion for Ren'Py

Comprehensive set of features to improve controller support in Ren'Py. · By Feniks

Need Support? Post here! Sticky

A topic by Feniks created Feb 09, 2025 Views: 2,104 Replies: 59
Viewing posts 1 to 18
Developer (1 edit)

If you're having trouble or run into any bugs with the code, post a comment here! I will try to get back to you within a few days. Be sure to check the Controller Support Expansion section on my website too for documentation.

So I finally got around to testing this out! Unfortunately, I immediately ran into a crash:

I'm sorry, but an uncaught exception occurred.
While running game code:
  File "game/script/system/plugins/controller_support/controller_config.rpy", line 313, in script
    init 999 python in pad_config:
  File "game/script/system/plugins/controller_support/controller_config.rpy", line 313, in script
    init 999 python in pad_config:
  File "game/script/system/plugins/controller_support/controller_config.rpy", line 316, in <module>
    FOCUS_MANAGERS = [FocusManager(x) for x in RESTORE_FOCUS_SCREENS]
  File "game/script/system/plugins/controller_support/controller_config.rpy", line 316, in <lambda>
    FOCUS_MANAGERS = [FocusManager(x) for x in RESTORE_FOCUS_SCREENS]
  File "game/script/system/plugins/controller_support/controller_config.rpy", line 316, in <listcomp>
    FOCUS_MANAGERS = [FocusManager(x) for x in RESTORE_FOCUS_SCREENS]
  File "game/script/system/plugins/controller_support/controller_functions.rpy", line 339, in __init__
    self.is_showing = renpy.get_screen(self.screen)
Exception: Unknown layer 'game_menu'.

I'm using a custom layer for my in-game menus (including the main menu), and that seems to be causing a problem.

Developer

Ooh I see! Yes I had not accounted for that. For now, can you see if this change to the FocusManager class in controller_functions.rpy will fix it?

def __init__(self, screen, layer=None):
    if isinstance(screen, tuple):
        self.screen = screen[0]
        self.layer = screen[1]
    else:
        self.screen = screen
        self.layer = layer
    self.is_showing = renpy.get_screen(self.screen)
    self.displayable_lookup = dict()
    self.refresh_triggered = False
    super(FocusManager, self).__init__()

And then adjust `RESTORE_FOCUS_SCREENS` to be a list of pairs like ("game_menu", "MY_GAME_MENU_LAYER") e.g.

define pad_config.RESTORE_FOCUS_SCREENS = [ ("main_menu", "my_menu_layer"), ("game_menu", "my_menu_layer"), "controller_remap" ]

I'll run some more tests and such, but try that for now. That, or if you're not using a game_menu screen/standalone like the template does, just remove "game_menu" from RESTORE_FOCUS_SCREENS altogether.

(1 edit)

Sadly, that didn't change anything. It still throws the same error (just with different line numbers, due to the few that were added).

I can only get the game to boot up by removing the "main_menu" AND "game_menu" part from RESTORE_FOCUS_SCREENS.

It also works if I remove [layer "game_menu"] from my "main_menu" screen  and do:

define pad_config.RESTORE_FOCUS_SCREENS = [ ("main_menu", "game_menu"), "controller_remap" ]

So it seems like it doesn't really care what I put in the tuple?

Developer

If your layer is called `game_menu`, renpy.get_screen is interpreted first as a tag and then as a screen, so regardless it wouldn't work with a screen *and* a layer called game_menu. So, I recommend either changing the tag name or the screen name so they're different if you want to use the save-and-restore focus features for the in-game menu screen. Otherwise, it's fine to just not have that screen in the RESTORE_FOCUS_SCREENS.

Hmm, the crash still occurs even after renaming my "game_menu" layer to "menus". But I'll keep testing with just 

pad_config.RESTORE_FOCUS_SCREENS = [ "controller_remap" ] 

for now. Thank you!

Hi, was looking at the demo template. Turning on self voicing when any of the custom preference screens open gave this if it detects mouse currently being used. Didn't happen when using keyboard/roller though.

I'm sorry, but an uncaught exception occurred.
While running game code:
TypeError: 'dict_values' object is not subscriptable
Developer(+1)

Huh, I had not noticed this! You are correct. The solution is to update the visit method in 01_controller_cdsl.rpy:

def visit(self):
    return list(self.displayables.values())

to wrap the return value in a list. I'll add this to the next fix release. Thanks!

Hi, is there any way I can disable the reset-to-middle aspect of the virtual cursor?

Developer

What kind of functionality are you looking to replace it with? Are you referring to how the cursor begins in the center of the screen, or the snap-to-center feature?

I thought it'd be nice to have the cursor available during regular dialogue (to click buttons in the quick menu with the cursor), but every time you advance the dialogue, the cursor resets back to the center of the screen.

Not a huge deal at all, just something I'm curious about.

Developer

How have you declared the cursor/added it to the screen?

Hi! First, I'd like to say your expansion is incredible! It's exactly what I needed, so thank you :-) Second, I had a quick question about the virtual cursor.  I may be overlooking something obvious (if so, my bad!!!), but I'd like the cursor to 'remember' its position if that makes sense. Rather than return to its predetermined position after pressing a button, I'd like it to stay put - basically updating its position to wherever the player pressed. I played around with the code for a little while but I can't seem to figure it out! Any suggestions? Thanks in advance for the help!

Developer

Hey there! The cursor should already stay put by default - do you have an example of code where you're seeing this behaviour?

Sorry for the slow reply! The code you've created is completely untouched - I reverted all the changes after messing around (even replaced the 01_virtual_cursor.rpy file with an untouched version just to make extra sure). The place I'm seeing this behavior in-game is during an investigation segment which uses image buttons inside a screen. This code is in screens.rpy and it looks like this:

I'll then call the screen in-game and use a series of labels to jump to each event like this...which I'm just now realizing is exactly my problem!!! When the event jumps back to the broom_nav label, the screen is called again, resetting the position of the cursor. 

Clearly there's a better way to code this that I didn't come up with the first time around (I'm self taught okay...) so I'll look into that! If you have any pointers you'd like to share, I'd really appreciate it. Otherwise, no pressure! You've helped me enough by making the perfect expansion :-)

Developer

No worries! I will look into adding a built-in feature so that the screen language version can save its position between being shown - there is already a property to indicate the starting position, so the only addition would be to save the current position somewhere so that it can be re-applied when the screen is shown again. In the meantime however, you can declare the cursor in Python with default, which will save it! e.g.

default vc = VirtualCursor(cursor=(Transform("gui/window_icon.png", xysize=(50, 50)), 0, 0))
screen investigation():
    vbox:
        spacing 100 align (0.5, 0.9)
        textbutton _("Hello") action Notify("world")
        textbutton _("Jump") action Jump("bedroom")
    add vc

The `add vc` bit adds the cursor to the screen, just like the `virtual_cursor` line. You can add whichever properties you like in the vc declaration e.g. `VirtualCursor(cursor=<...>, snap_to_center=True, which_stick="left")`

Hope that helps!

Wow, this works perfectly! Thank you for taking the time to look into this - I really do appreciate it! 

(+1)

Hi, thanks so much for creating such a great expansion. 

Unfortunatly I ran into a few issues. When using the ESC key on keyboard, or the little menu button on my ps5 controller a bug appears that it hadn't before.  "An exception has occured. While running game code: File "renpy/common/00gamemenu.rpy" line 174 in script $ui.interact() TypeError: missing a required argument 'title'" 

This immediatly pops up if one of those buttons is pressed, and while I didn't check the controller without the expansion, I remember the ESC worked normally before . 

Then, whenever I mess up code (which is a lot lol), instead of renpy showing me where I messed up, everything is closed down and this is shown in my code editor: "I'm sorry, an uncaught exception has occured. After loading the script. File "game/backend/backend/controller_support/controller_override.rpy", line 196, in my_controller_event    NameError: name 'CONTROLLERDEVICEADDED' is not defined" Not sure if that's normal? 

And then I have a question regarding putting a controller_viewport   in the game menu screen. It seems like when I replace the normal viewport with the controller one there *is* a functioning scrollbar in all the game menus,... however you can't visually see it. I narrowed down the deciding component being "side_yfill True", without it even the normal viewport won't show the scrollbar, however controller viewport doesn't seem to support that property, and normal yfill True does nothing. 

Oops, I realize this was a whole wall of text, but I hope you can still help me out. Thank you so much in advance.

Developer

No worries! This is something I'm looking to update the files to make it a bit easier to understand - by default, the controller pack sets the game_menu screen to be opened when you hit the game_menu shortcut button (e.g. Start/ESC/right click). In the template, this is made possible by setting `title` as a keyword argument rather than a required argument, hence the error complaining about requiring the title argument.

You can remove or adjust this line `_game_menu_screen = "game_menu"` and/or adjust `screen game_menu` to have `title=""` instead of just `title` as an argument.

As for the error, you can put this into the my_controller_event function:

try:
    cda = CONTROLLERDEVICEADDED
except NameError:
    ## Probably reporting some other error
    return rv

put it just above the `if ev.type == CONTROLLERDEVICEADDED:`

To be fair this may not solve all problems with error reporting - the main issue is just that Ren'Py tries to make an error message and skips over various other steps like declarations, which means it then gets caught on otherwise normal parts of the code. So that check is an attempt to ignore that particular problem if it arises, but it's possible it'll try throwing an error somewhere else instead.

And for the viewports, `controller_viewport` does not handle `side_` properties or automatically adding scrollbars unfortunately, so you'll need to explicitly set that up/add it instead. Notably, the following are equivalent (aside from the controller_viewport bit being a controller-compatible viewport obviously):

viewport:
    scrollbars "vertical"
    side_yfill True
side 'c r':
    yfill True
    controller_viewport:
        id 'whatever'
    vbar value YScrollValue("whatever")
Hope that helps!
(+1)

Thank you so much  for the help! I really appreciate it.

Just as a side (ha) note in case ppl in the future read this: side 'c r' gave me real trouble until I substituted the quotes with double quotes like this : side "c r".  The rest is correct and was an awesome help. My issues are pretty much gone now, thx again. :D 

Developer

Hmm, are you certain that was the cause? Double and single quotes are interchangeable in Ren'Py in most cases for denoting strings, and I pasted the code into script and didn't have any problems running it. If you got an error, feel free to post it!

Happy to hear your other problems were resolved as well ✨

Deleted 163 days ago
Developer

The first one is really out of the scope of what I can help with for this tool. You can potentially look into nearrect for positioning the new screen appropriately, or style your buttons instead of opening a new screen.

For your second question, you can use buttons that have the Scroll action, if I understood you. Generally if they're using the mouse though, it won't make sense to have buttons which set focus elsewhere. You might be better served having a variable keep track of what button is "selected" and style it based off of selectedness rather than hover state. Then you can execute the appropriate button action based on which button is selected.

Deleted 163 days ago
(1 edit)

Hello! I've been trying out the controller system, and I'm currently developing some minigames for my VN, currently the buttons for my minigames were pygame-mapped keys. I tried to use the add_custom_event in order to map my game to new custom events but I ran into some issues. Is there a way to isolate events for a specific screen? 
Supposedly, my events should be categorized as in-game. The problem is that anything I map to it will remove it from another in-game action (let's say my walk action or hit action will delete confirm or advance dialogue default button mapping). And if I manage to get them to work by using the "always" category instead of the "in-game" for my custom event, when I run my game screen, it will do both the in-game action and skip over the always action. 
For this specific screen, I dont really need any of the scroll forward, auto, or any of the in-game default events, as my screen is used for the minigame only (we dont save, reload, auto fordward or do any other Ren'Py action that is not a custom action for the minigame.) Once my game is over, my screen disappears and returns to the normal dialogue screen.

Developer

If anything, this sounds like it would be a "situational"-category event, given that it's only active during minigames. You're also welcome to add your own categories and define their compatibilities when you add new events. Or, if you don't need your minigame keys to be remappable, it's fine to just hardcode it with pygame events.

Deleted 163 days ago
Developer

Have you tried this with a general viewport? Ren'Py doesn't pass ATL events to displayables inside containers, so that may be what you're seeing. Otherwise, if it works with a regular viewport and not the controller viewport, if you can make me a short reproducible code section I'll look into debugging it.

Deleted 163 days ago
Deleted 163 days ago
Deleted 163 days ago
Developer

I've got it on my to-do! Unfortunately I just have a lot of things to do 😅 But it's in the issues page of my repo. The example you gave was missing a few things for me to make it run properly, but I was able to reproduce a pretty basic example by popping some ATL on buttons in a controller viewport. I will let you know if I have any updates!

I have a question regarding the ongoing port of Renpy to SDL3 (See Renpy Dev update for February 2026). With this expansion being based on SDL2, do you think it's likely that it won't work on Renpy 8.6 and beyond? Even with Renpy 8.5 pygame_sdl2 was removed. Is that of relevance for this project? Can you recommend a version of Renpy that will definitely work with it? Thanks you in advance!

Developer(+1)

I'm not really concerned about this, no. Ren'Py's developers value backwards compatibility, so it's unlikely we're going to lose functionality. If some parts need tweaking following the change, I'll simply make an update to the tool, and you would be able to continue using this initial version on any earlier Ren'Py engine releases. In general I try to avoid modifying engine internals wherever possible, and if I do (often to fix bugs) I always ensure that if I need to change how the tool accesses that part, your "front-end" code using my tool won't have to change. So, I wouldn't be worried about it.

Hi, I have an issue - well, two issues, but I'm taking one at a time.

This first one is an error that pops up when I press the Escape key while in game:

I'm sorry, but an uncaught exception occurred.
While running game code:
NameError: name 'viewport' is not defined. Did you mean: 'Viewport'?
-- Full Traceback ------------------------------------------------------------
Traceback (most recent call last):
  File "renpy/common/00gamemenu.rpy", line 174, in script
    $ ui.interact()
  File "renpy/ast.py", line 1187, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/python.py", line 1273, in py_exec_bytecode
    exec(bytecode, globals, locals)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/common/00gamemenu.rpy", line 174, in <module>
    $ ui.interact()
      ~~~~~~~~~~~^^
  File "renpy/ui.py", line 306, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 2154, in interact
    repeat, rv = self.interact_core(
                 ~~~~~~~~~~~~~~~~~~^
        preloads=preloads,
        ^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "renpy/display/core.py", line 2700, in interact_core
    root_widget.visit_all(lambda d: d.per_interact())
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/displayable.py", line 457, in visit_all
    d.visit_all(callback, seen)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "renpy/display/displayable.py", line 457, in visit_all
    d.visit_all(callback, seen)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "renpy/display/displayable.py", line 457, in visit_all
    d.visit_all(callback, seen)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
[Previous line repeated 1 more time]
  File "renpy/display/screen.py", line 503, in visit_all
    callback(self)
    ~~~~~~~~^^^^^^
  File "renpy/display/core.py", line 2700, in <lambda>
    root_widget.visit_all(lambda d: d.per_interact())
                                    ~~~~~~~~~~~~~~^^ 
  File "renpy/display/screen.py", line 514, in per_interact
    self.update()
    ~~~~~~~~~~~^^
  File "renpy/display/screen.py", line 715, in update
    self.screen.function(**self.scope)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "renpy/parameter.py", line 468, in apply_arguments
    return parameters.apply(args or (), kwargs or {}, ignore_errors)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/parameter.py", line 401, in apply
    self.apply_defaults(arguments)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "renpy/parameter.py", line 221, in apply_defaults
    val = param.default_value(locals=scope)
          ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "renpy/parameter.py", line 58, in default_value
    return renpy.python.py_eval(self.default, locals=locals, globals=globals)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/python.py", line 1305, in py_eval
    return py_eval_bytecode(code, globals, locals)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/python.py", line 1298, in py_eval_bytecode
    return eval(bytecode, globals, locals)
           ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<none>", line 1, in <module>
NameError: name 'viewport' is not defined. Did you mean: 'Viewport'?
Windows-10-10.0.19045-SP0 AMD64
Ren'Py 8.5.2.26010301

I probably didn't set something up correctly somewhere, but I'm not exactly sure where. I could use a pointer on where I might have made a mistake.

Developer

If you're plopping this into an existing project, you probably don't want to take the screens with it! Or make sure you just have one copy of the screens. While the error message doesn't specify, I imagine you might be running into an issue where the game_menu screen included with this project doesn't have some of the arguments that the game_menu screen in a default Ren'Py template has. 

That actually helped me fix the issue! While it was not directly an issue of me having two game_menu screens, looking over my game_menu screen made me find the root issue.
My game_menu screen was set up like this:

screen game_menu(title="", scroll=viewport, yinitial=0.0)

 
and that's where the game was asking me to capitalize the viewport, so I did:

screen game_menu(title="", scroll=Viewport, yinitial=0.0)


and that fixed it. That was just the pointer I needed.
---------------------------------------------------------------------------------------------------
Now for my second problem: When trying to open the help menu window specifically using a controller, I am getting this error:

I'm sorry, but an uncaught exception occurred.
While running game code:
  File "renpy/display/render.pyx", line 494, in renpy.display.render.render_screen
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 320, in renpy.display.render.render_for_size
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "game/01_high priority/01_controller_cdsl.rpy", line 808, in render
    self.reset_child()
    ~~~~~~~~~~~~~~~~^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 791, in reset_child
    self.set_saved_icon()
    ~~~~~~~~~~~~~~~~~~~^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 798, in set_saved_icon
    self.saved_icon = self.get_icon(self.suffix, self.icon_only)
                      ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 822, in get_icon
    event = pad_config.get_event(self.pad_event)
            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "game/backend/controller_support/controller_functions.rpy", line 121, in get_event
    events = persistent.pad_bindings[event]
             ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: None
-- Full Traceback ------------------------------------------------------------
Traceback (most recent call last):
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "renpy/ast.py", line 1187, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/python.py", line 1273, in py_exec_bytecode
    exec(bytecode, globals, locals)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
    ~~~~~~~~~~~^^
  File "renpy/ui.py", line 306, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 2154, in interact
    repeat, rv = self.interact_core(
                 ~~~~~~~~~~~~~~~~~~^
        preloads=preloads,
        ^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "renpy/display/core.py", line 2833, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 1279, in draw_screen
    surftree = renpy.display.render.render_screen(
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        root_widget,
        ^^^^^^^^^^^^
        renpy.config.screen_width,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
        renpy.config.screen_height,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "renpy/display/render.pyx", line 494, in renpy.display.render.render_screen
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 896, in render
    surf = render(child, width, height, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/transition.py", line 375, in render
    top = render(self.new_widget, width, height, st, at)
          ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 896, in render
    surf = render(child, width, height, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 896, in render
    surf = render(child, width, height, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/screen.py", line 767, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 896, in render
    surf = render(child, width, height, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1444, in render
    surf = render(child, width - cxmargin - cxpadding, height - cymargin - cypadding, st, at)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1104, in render
    surf = render(d, rw, height - y, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1444, in render
    surf = render(child, width - cxmargin - cxpadding, height - cymargin - cypadding, st, at)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1955, in render
    cwidth, cheight = sizeit("c", width, height, 0, 0)
                      ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/layout.py", line 1952, in sizeit
    rend = renpy.display.render.render_for_size(pos_d[pos], width, height, st, at)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 320, in renpy.display.render.render_for_size
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/viewport.py", line 283, in render
    surf = renpy.display.render.render(self.child, child_width, child_height, st, at)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1159, in render
    surf = render(d, width - x, rh, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1159, in render
    surf = render(d, width - x, rh, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "renpy/display/layout.py", line 1104, in render
    surf = render(d, rw, height - y, cst, cat)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/render.pyx", line 170, in renpy.display.render.render
  File "renpy/display/render.pyx", line 267, in renpy.display.render.render
  File "game/01_high priority/01_controller_cdsl.rpy", line 808, in render
    self.reset_child()
    ~~~~~~~~~~~~~~~~^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 791, in reset_child
    self.set_saved_icon()
    ~~~~~~~~~~~~~~~~~~~^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 798, in set_saved_icon
    self.saved_icon = self.get_icon(self.suffix, self.icon_only)
                      ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "game/01_high priority/01_controller_cdsl.rpy", line 822, in get_icon
    event = pad_config.get_event(self.pad_event)
            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "game/backend/controller_support/controller_functions.rpy", line 121, in get_event
    events = persistent.pad_bindings[event]
             ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: None
 
This error notably does not appear when navigating to the help screen using mouse or keyboard, using these methods shows the help window just fine, it only throws this error when using a controller to try and open the help window. I should also note that I have the keybind images from the controller_ui folder visually displayed on the help screen, in case that might be relevant.
Developer

Ah it should be `scroll="viewport"` as a string. The fact that it doesn't complain about Viewport is just 'cause you're setting it to the name of a class, which does exist, but isn't what the screen is expecting.

Have you updated ICON_FOLDER = "backend/controller_support/controller_ui/" at the top of controller_config.rpy to point to where you have the controller icons? It looks like you've put the files into your own subfolder, so you'll need to update the path where it can find the icons as well.

The icons are actually still in the backend folder. I made a separate folder for a few certain files in your pack to be higher up in the sorting order as they seemed to be conflicting when further down in the backend folder, since I have several order numbered folders in my game folder.


These are the files I have moved higher so they execute early enough:


And these are the files left in the actual backend folder:


So the icons are actually still in the backend folder.
Still, I tried copying the controller_ui folder over into my higher priority folder real quick and changed the file path to that to see if this was maybe a priority issue too, but the error message remained.

Developer

Have you modified or removed custom events, or added your own icon buttons to the screen? It looks like it's trying to find a pad event, and there isn't a match.

I don't believe I've removed any custom events, though I did make 4 new .svg button images for the m, n and p keys, as well as all the arrow keys together. Defined them in the controller_icons.rpy as well, this is the relevant code I've added for them there:
 

define icn.mute = IconButton("ToggleMute", ["m", "M"], _(""), "key_m")
define icn.arrowkeys = IconButton("", ["K_LEFT", "K_RIGHT", "K_UP", "K_DOWN"], _(""), "key_arrowkeys")
define icn.n = IconButton("", ["n", "N"], _(""), "key_n")
define icn.p = IconButton("", ["p", "P"], _(""), "key_p")
Developer

Ah, I see - none of those buttons have valid controller events. Thus, the game has no way to look up events associated with those buttons. IconButton is intended to have a mapping both for keyboard and for controller. If you just want to make a mouse & keyboard button with no controller equivalent, there's no need to use IconButton at all, since most of its conveniences are tied to picking the right icon set and allowing for remapping, none of which is offered for keyboard shortcuts. You can just make your own imagebutton with a keysym.

Ohh, I see! That makes sense, also explains the issue. After replacing the icon buttons with imagebutton equivalents, the issue has now resolved itself. Thank you for all of your help!

(1 edit)

Thanks for your work on this extension. It's extremely impressive.
Unfortunately I have ran into an issue with a horizontal bar nested within a controller_viewport. The video should make it clear, but it's that these bars behave differently depending on if they are just in a vbox, in a regular viewport or within a controller_viewport. It behaves normally when used with a controller. The game's resolution is 3840x2160 in case that matters. I've been banging my head against this issue for the last couple of hours and I can't seem to solve it. 

vbox:
    spacing 50
    hbox:
        label _("TEXT SPEED")
        null width 50
        controller_bar value Preference("text speed") alt "Adjust Text Speed" style "preferences_slider" yalign 0.5
        label " <- NOT in controller_viewport" yalign 0.5
    viewport:
        hbox:
            label _("TEXT SPEED")
            null width 50
            controller_bar value Preference("text speed") alt "Adjust Text Speed" style "preferences_slider" yalign 0.5
            label " <- in regular viewport" yalign 0.5
    controller_viewport:
        id "pref_display_vp"
        xsize 2500
        mousewheel True
        draggable renpy.variant("touch")
        vbox:
            spacing 50
            hbox:
                label _("TEXT SPEED")
                null width 50
                controller_bar value Preference("text speed") alt "Adjust Text Speed" style "preferences_slider" yalign 0.5
                label " <- in controller_viewport" yalign 0.5


Developer

Thanks for the detailed bug report!

I'm currently investigating this; I don't have any particular answers yet, though the problem appears with a regular bar as well as a controller bar, so it seems to be a problem specific to the controller viewport. Strangely, it doesn't always appear either - you'll notice that the bars that come with the preference screen included in the template don't have this problem. I've been able to tentatively narrow it down to something going wrong in the render method. I'll keep plugging away at it when I have time. In the meantime, you might play around with copying over the preference screen controller_bar layout and adjusting it to find a version that works.

Developer(+1)

Spoke too soon actually; try replacing the following function with these modifications:

def get_all_children(d, xoffset, yoffset, width, height):
    """Return all the children, grandchildren etc of d."""
    children = [ ]
    offsets = [ ]
    sizes = [ ]
    if not hasattr(d, "children"):
        return children, offsets, sizes
    for i, child in enumerate(d.children):
        ## Render it to get the size
        # cr = child.render(width, height, 0, 0) ## Caused some weirdness with bars
        cr = renpy.render(child, width, height, 0, 0)
        sizes.append((cr.width, cr.height))
        children.append(child)
        offsets.append(d.offsets[i])
        if hasattr(child, "children"):
            ch, of, sz = get_all_children(child, d.offsets[i][0], d.offsets[i][1], cr.width, cr.height)
            children.extend(ch)
            offsets.extend(of)
            sizes.extend(sz)
    new_offsets = [ ]
    for of in offsets:
        new_offsets.append((of[0]+xoffset, of[1]+yoffset))
    return children, new_offsets, sizes

Let me know if that fixes your problem. I still need to do a bit more testing to make sure other aspects of the viewport work as expected, but this did solve the bar problems for me.

Thank you so much! This instantly fixed the issue for me!

It's a bit of weird one. The bars with custom bar value objects never exhibited that issue, but the bars using Preference values like the ones for the audio controls definitely did for me. So the ones provided in the expansion like "Left stick sensitivity" never had this problem cause they use custom classes inherited from BarValue. Making python classes inherited from BarValue was the workaround I have found to work. I tried that for the volume sliders, but it can be a bit funky sometimes and the value can sometimes jump around oddly.
Anyways, thanks again and thank you for the effort you put into this project!

Deleted 163 days ago
Developer

Is it just that the viewport is centering on the button when it's re-selected? Obviously without a visual it's hard to tell; one thing of note is that all grid squares will have the exact same size, which isn't true of hbox, which may be a reason for the discrepancy in behaviour.

Deleted 163 days ago
Developer

Ah, you're using a transform that is changing the size of the displayable. Can you try putting it inside a fixed with a set size (the maximum size of the card when it's not being flipped)?

Deleted 163 days ago
Developer

What exactly does your code look like?

Deleted 163 days ago
Developer

Show the actual code, please.

Deleted 163 days ago
Developer

What do your ATL transforms look like?

To be honest, I'm not sure this is a good use case for the controller viewport, or even a viewport at all. Given the animations you want to do, I'd probably just manually assign left/right to swap whatever card is in the center, and use ATL animations to move them to the right location. The cards wouldn't even need to be buttons; you can just have a variable track which one is selected and perform an action accordingly when the button_select action is performed.

Deleted 163 days ago

Hello! 2 (mostly) new questions.
1) The base controller expansion is working well except for in a character creation screen with your Colorpicker on it. Do I need to add something manually to make sure it's available there?
2) Possibly a question with a similar answer. I did end up making a MouseVCursor method but I wasn't sure how to get it initialized to run with every screen and I'm afraid the internet has not helped much other than making sure it's in an early block. I manually set it up in a screen as such, but obviously it doesn't run in menus and pop ups:

screen mouse_sensitivity:
    virtual_cursor:
        id "VirtualCursor"
        cursor ("cursor", 12, 30)
        cursor_area (0, 0, config.screen_width, config.screen_height)
        hide_on_mouse False  # keep vcursor visible even when mouse moves
        which_stick "both"
        speed 1000.0
    add MouseToVCursor("VirtualCursor", *pygame.mouse.get_pos())

The method just captures a MOUSEMOTION event and applies the sensitivity multiplier before rendering the scene. Is this because the virtual cursor doesn't exist/run on top of menus and pop ups?

Thank you again for your help.

Developer

For the colour picker - are you using the controller version? I put out an update with color_picker_controller.rpy which you'll need to use if you'd like the bars and color picker navigation to be able to be navigated via controller.

For your screen - I think you'll want something like the event_listener screen in the controller pack, which sits on top of everything. It's added to config.always_shown_screens. If you want this mouse to work everywhere, I believe you will need to grab the mouse events and then send out a modified mouse event, otherwise you are not going to be able to do things like click and drag bars, drag and drop, or viewports. I get around this with the virtual cursor by making it a container you can put the screen stuff inside, because most games won't have a virtual cursor to navigate their entire game, and then I can pass along fake mouse events to the container's children. You're probably going to need to pass along adjusted mouse events to the entire game. I'm afraid this is about the extent to which I can assist you in this matter, however, as your question is no longer related to my tools. 

Deleted 163 days ago
Developer

It should be at the top level, so, not inside a frame. You can certainly adjust the area so it appears to be inside a frame.

(1 edit)

Short version: I used `controller_bar` but values are not changing.

Longer version: I can't come up with a minimum replicable case, so I'm a bit bamboozled about where the problem is arising, and I don't want to copy/paste my whole project code. My preferences screen started out similar to the default renpy project, but I changed the viewport-based scroll to a `controller_viewport` and the preferences bars to `controller_bar`s. I set up a `FocusDisplayable` object, so I know that the bar is currently focused, and even though pressing left/right doesn't change the focused object, it also doesn't change the value on the bar.

Developer

Unfortunately there isn't really any information for me to troubleshoot with either; I suppose for you I'd suggest just adding or removing things one at a time. Perhaps try removing the FocusDisplayable, making the controller_viewport just a regular viewport, removing other things from your viewport and screen, changing the bar to a regular bar, etc. 

Alright, I figured it was worth asking at first in case there was some known incompatibility. I did some additional testing and found the source of the issue: the viewport attribute `arrowkeys: "not sticks"` breaks both `bar` and `controller_bar` elements inside of it.

Developer

Thanks for the investigation! I've added it to my issues tracker and I'll take a look when I can.

Hey! Sorry for the stupid question, but I'm trying to display a tooltip at the position of the virtual cursor but I can't figure out how to access its position. 

Developer

No worries! Simplest way will be to add this function somewhere:

def get_vc_position(id):
    """Get the position of the virtual cursor with the provided ID."""
    d = renpy.get_widget(None, id)
    return d.get_cursor_coords()

And then you can give your virtual cursor an ID and pass it into that function to get the current coordinates.

Thanks so much! I've just tried this and am getting the error:

AttributeError: 'NoneType' object has no attribute 'get_cursor_coords'

I called the function with:

vc = VirtualCursor()
renpy.show_screen("locked_tooltip", data.title, vc.get_vc_position(id), data.unlocked)

Sorry if i'm missing something super obvious!

Developer

To be clear - the point is to give an existing virtual cursor an id like id "whatever" and you pass in "whatever" to the function I wrote. Do not create a random virtual cursor and try to get coordinates from it - the one you made in your example code isn't shown anywhere and thus any information it had would be entirely useless, even discounting the fact that the function I made wants an ID and not a VirtualCursor object. If you already have a Python VirtualCursor object defaulted instead of declared via virtual_cursor in a screen, then just call get_cursor_coords() on your VirtualCursor object. Again, do not just create a random VirtualCursor object - this must be the virtual cursor you are already using.

Ah, I got it working, thanks again! I'm not used to this kind of thing, thanks for providing such an indepth tool.