Posted May 07, 2020 by Marquis Kurt
#minigame #python #devlog
The latest builds of the Unscripted Extended Demo include a brand new minigame that challenges you to collect all of the coins and navigate to the exit with a series of commands, but did you know that you can take it up a notch and supercharge the minigame with Advanced Mode? Fear not; this devlog will show you some of the perks Advanced Mode has.
Advanced Mode is a special mode of the Unscripted minigame that lets you be more in creative in how you solve the puzzles by giving you the ability to write Python code that works with the game. You can take advantage of what Python has to offer with the official interface to access the minigame (API), Fira.
Itās easy to get started with the Advanced Mode of the minigame! Just go to Settings āŗ Minigame and turn on Advanced Mode to get started. In the minigame settings, you can also open the folder where the Python scripts live and open the documentation that comes with the API.
When a minigame level appears, instead of seeing the buttons to control Mastiās movements, youāll see a bigger version of the world with buttons in the toolbar to open the scripts folder, get help via the documentation, and run your Python script:
On the minigame screen, click āOpen Folderā to open the Python scripts folder in the File Explorer on Windows, Finder on macOS, or your file browser of choice on Linux.
There will be several files for the minigame levels, each numbered by their level. The count starts at zero and increments by one for each level. If youāre unsure of what level you need to write a script for, check the title and level number of the current level youāre on in the minigameās toolbar.
Each minigame level script comes preloaded with some template code to get you started. Namely, the game attempts to get the playerās information and the world from the minigameās levels:
# Import the level information APIs.
from uvn_fira.api import get_level_information, CSPlayer, CSWorld
# Get all of the information for this particular level.
game_player, game_world = get_level_information(0, fn_path=renpy.config.savedir + "/minigame/", exists=renpy.loadable, load=renpy.exports.file) # type: (CSPlayer, CSWorld)
In most cases, you should probably not remove the code from these files; otherwise, you may run into some problems when trying to get your player to move!
Now letās get into writing some code to solve the first puzzle! There are two main objects we can currently work with: game_player
, which controls the player, and game_world
, which controls the world. Most of the time, youāll just need to work with the game_player
object since you need to move the player and collect coins, but you can use game_world
to determine things about the world that may help you.
In the first puzzle, we need to move Masti to the exit at the end of the corridor. In the basic mode, you would need to press āMove eastā four times and then press āExit mapā. game_player
has a function called move
that moves the player a given direction that is supplied as a parameter. The exit
function exits the map and also write the respective code for the minigame to read, so make sure that your scripts end with game_player.exit()
! With this knowledge, we can write the following code to achieve the same effect as before:
game_player.move("east")
game_player.move("east")
game_player.move("east")
game_player.move("east")
game_player.exit()
Great, weāve written some code that works! Letās take advantage of Pythonās looping abilities with a for
-loop to run that same code four times:
for _ in range(4):
game_player.move("east")
game_player.exit()
Run it through the game, and keep experimenting with it to solve the puzzle.
If you get stuck, you can always make use of the documentation, which tries to be an informative source of whatās available to you. To access the documentation, you can click āHelpā in the minigame toolbar, go to Help āŗ Documentation in the game menu, or click āOpen Documentationā in Settings āŗ Minigame. You can also read the documentation on the website for the minigameās source code: https://fira.marquiskurt.net/api/.
If you need some live help from fellow players or the development team, chat with us on Discord! Weād be more than happy to help you and look at your code. Hereās the invite link if youāre not in the server already: https://discord.gg/CXxnVhX.
Now that you can write Python for the minigame, there are many ways that you can make the experience more comfortable for you as a developer! Hereās a great couple of notes to consider:
pip install uvn_fira
. This works great if you want to use tools like Poetry or pipenv
to create an environment for you to write your code in!I hope you have fun playing around with what Python has to offer in the Advanced Mode of the minigame. Good luck; now go write some awesome Python code!