Ren’Py Claw Machine Mini-game Script
I’m sure most people have come across a claw machine in their days where you control this mechanical arm and then press a button to try and grab a prize. As I was brainstorming ideas for new mini-game to make in Ren’Py, I thought this would be an excellent idea for visual novels where a character goes to an arcade or similar.
This script is available to all patrons in the tier Voting-power or higher over at my Patreon page. I have written an entire PDF documentation that comes with it as well, which tells you more about how the code works. Below is a preview video and below that a short summary of how it works.
To make it work in a 2d environment, I decided to only make the arm move right and left with the arrow buttons on the keyboard, and you can only play it if you have input enough coins. Each game costs x amount of coins which you can set to whatever amount you like. In the example script it costs 10 coins to play.
For the movement to work, I decided to go with transforms using transform functions. These functions continuously runs and checks if the player is pressing the right or left arrow keys.
To detect key presses, I simply used key displayables inside the mini-game screen itself. These key displayables then set a variable to either “right” or “left”, which we can then check inside the transforms to move the arm. Same for grabbing an item. There’s a key displayable that listens for a specific key press, and then the relevant transform function listens for a variable value set by the displayable action, and then runs it’s code to move the arm down and rotate the claw parts.

The prizes are randomly picked using Python’s random “choices” function together with cumulative weights. This way one can decide how likely a price is to be picked or not. If you haven’t dabbled in the choices function yet using weights, it might be an interesting topic to learn more about if you’re interested in coding random things for your games! 😊
If you decide to get the script, you can of course modify it however you like to fit your game and swap the images for something much better looking than this example!
The script can be downloaded from my Patreon page for anyone in the tier “Voting-power” or higher. Join and stay for however long you want. 😁 There’s many more scripts and also some in-depth written tutorials over there that you might find interesting.

Leave a Reply