Python Tutorial 1: Setting Up PyCharm

= Python Tutorial 1: Setting Up PyCharm =

Why PyCharm?
Editing Python without specialised tools can be really laborious: indentation and syntax errors you don't find out about until you run it and so forth. With a bit of up-front setup, you can save yourself a lot of time. If you prefer another IDE over PyCharm (like VS Code, say), most of these instructions can be adapted for that program too.

Benefits:
 * Warns you about a wide range of errors as you type.
 * Spelling and grammar checking.
 * Quickly jump between definitions of things and their usages.
 * Shows you what's happening in the program at the point it crashes (a debugger)

Setting Up PyCharm
You will need to have installed:
 * A Python 3.7 32-bit installation
 * Yes really 32-bit, the dependencies included with Fleshcult are all 32-bit.
 * Take a note of where you install this, you'll need to find it later.
 * PyCharm Community Edition or better.
 * A zip utility, like 7-zip, say.

Steps:
 * Make a copy of the fleshcult folder so you're not like, trying to put your stuff in a place that Steam or the Itch App will overwrite.


 * Using 7-Zip (or similar), right click on fleshcult.nut in the game folder and select Extract Here. You'll see a faust folder appear in your game folder, amongst other things.


 * Delete fleshcult.nut to force it to use the unzipped code.


 * Launch PyCharm and select New Project.


 * Locate your copy of fleshcult in the file requester and select the game/ subfolder.


 * Set the python interpreter to Existing Interpreter and pick python.exe from your Python 3.7 installation. (The game comes with an interpreter, but it doesn't have the debugging stuff that PyCharm needs)


 * Yes to creating a project from existing sources. You should now see a Project sidebar full of files.


 * PyCharm has some popups about improving performance by disabling Windows Defender or downloading shared indices, but you don't care about any of that.


 * To run the game, you'll need a launch configuration. There's a hamburger menu at the top left, click it and go to Run -> Edit Configurations.


 * If you click the dinky little plus icon, it'll give you a range of templates you can use. Use the one called simply 'Python'.


 * Set the Script path, pick cef_main.py using the file requester/


 * Type  into the Parameters box


 * Hit Apply and close the window.


 * Notice how in the top toolbar your launch configuration is selected and there are Play and Debug icons up there.


 * Try clicking Debug now. The game should start.

Using PyCharm
If you've never seen a programming IDE before, this is probably a bit overwhelming, but PyCharm has extensive docs of its own. Here are some basics to get you started:
 * The game code is in the faust/ folder. If we wanted to look at player transformations, for example, that'd be in Transformations.py.
 * Ctrl-click on a function or variable to see the definition.
 * Ctrl-shift-F to search the project.
 * Yellow underlines are only warnings and won't crash. In particular the PEP 8 ones are just stylistic critiques and I've turned most of them off.

Using PyCharm to investigate a crash:
 * While stopped on at a crash (or breakpoint), you can hover over variables to see their values.
 * While the game is running, a big footer labelled Debug will appear. Notice how it has two sub-tabs: Debugger and Console. The Console shows you the log messages coming out of the game. If the game crashes or stops at a breakpoint, the Debugger lets you see which functions led to which other functions. Because it shows the Debugger first, so you'll have to switch to the Console to see the error message it crashed with.
 * The whole footer can be toggled on and off with the bug icon on the left edge of the window.
 * If you edit the code, your changes won't kick in until you restart the game.

What's Next
To write: Python Tutorial 2. Python Mod Skeleton Code, moving your changes out into a mod.