(Solved) How to do Automatic Controller Detection?

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
SypherZent
Veteran
Posts: 331
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Soundcloud: Chrysopoeist
Location: Puerto Rico
Contact:

(Solved) How to do Automatic Controller Detection?

#1 Post by SypherZent » Sat Oct 17, 2020 7:11 am

Okay, I need my game to automatically detect controller input the way AAA games are currently handling controller detection.

Here's how it goes: As soon as player presses any button on controller, a variable is set to a state where the game knows a controller is being used. If the player then presses any button on keyboard, or mouse, that same variable reverts back to detecting keyboard/mouse (no controller). This is used to display HELP guides (i.e. images that show buttons, where you explain to the user if they press a certain button, a certain thing happens).

For example, main menu, if the player presses ANY button on controller (usually DOWN to select New Game), I want an image to appear on the right that shows the Right Trigger RT button next to the thing it activates, and B button to Exit Game. If they then grab mouse and hover over anything or press DOWN on keyboard (instead of controller) I want those images to disappear. Handling everything is easy once I understand how to detect controller usage. If you want a specific example of a game that does this, Titanfall 2 does it exactly as I am describing. I think even their loading screens say 'Pressing (button) will (do this)' and the button changes from controller to keyboard depending on what the player last pressed.

So, how can I detect that the player last pressed a button on their controller and override this value if they last pressed a button on their keyboard?

I already have a worst-case scenario solution to do what I need, but I'm hoping there is a more optimal and straightforward way to do this than to run a screen action for every possible case, in every screen where I need the detection.

Thanks in advance for any help with this.


Solved
I worked around this issue by separating screen actions for gamepad from keyboard and using this to detect what was pressed, then switching the variable internally. For the image notation, I allow the user to select via Settings which type of controller they are using (i.e. PS4, XBox, NS).

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]