how do you make PYO files and also open and edit them if needed to make changes? also how to make a .script file so you don't need to put your files into a pyo file than doesn't need to be extracted?
This is the text file I made for myself with instructions that work for me: (NB you also need to get a file called unpyc.py which you can obtain from https://raw.githubusercontent.com/figment/unpyc3/master/unpyc3.py Just copy the text, paste it into your text editor and save it to filename "unpyc3.py")
The Sims 4 uses Python 3.3.5
=======================================================
To decompile the EA game scripts
2. Copy the .zip files in the game's "Data\Simulation\Gameplay\" folder into the folder, and extract each of them into their own folders. You should now have three sub folders, one called "base," "core," and "simulation".
3. Place the unpyc3.py into the folder.
4. Also place a .bat file with the following contents:
Code: @echo off
for /r %%i in (*) do unpyc3.py "%%i" > %%i.py
pause
5. Also place a .bat file with the following
Code:
REM Batch file for getting rid of the original .pyos and renaming .pyo.py to just .py
for /r . %%i in (*.pyo) do del "%%i"
for /r . %%i in (*.pyo.py) do ren "%%i" "%%~ni"
for /r . %%i in (*.pyo) do ren "%%i" "%%~ni.py"
pause
6. Run the first .bat file. You'll see some errors, but that's okay.
7. Then run the second .bat file.
========================================================
To compile your script
After you get your .py file, in order to get it to work you need to make a .pyo file and put that along with your .py file into a zip file. The zip file is what goes into your Sims 4 Mods folder. To make a .pyo file, you can create a batch file named something like PythonOptimizeCompile.bat and put this in it:
Code:
@echo off
if %1x==x goto usage
%~d1
cd "%~p1"
echo on
python -O -c "import py_compile;py_compile.compile('%~n1%~x1','%~n1.pyo')" @echo off
goto end
:usage
echo drag+drop the .py file onto this to compile to a .pyo file.
:end
pause
If you have more than one Python version installed and the version found by your path is not the version used by Sims 4 (3.3.5) then you will need to put the full path in for the python command rather than just "python" or change your path variable.
Then when you drag+drop your .py file onto that batch file it will create a .pyo file with the same base name as the .py file in the same folder, provided python is in your path. This applies to Windows.
=========================================================
Where to put your scripts so they will run
You can EITHER put the uncompiled .py in Mods/YourMod/Scripts OR you can zip the compiled .pyo into a zip file which you can optionally rename from .zip to .ts4script and this goes into Mods/Scriptmods or wherever else your other downloaded script mods are successfully running from.
Start a project
Get all subfolders and loose files out of core, simulation and base and put them in your project root
Mark all folders as source folders.
Add source folders to python path under Console in settings
Do File|Invalidate caches then the red wigglies will go
Comments
The Sims 4 uses Python 3.3.5
=======================================================
To decompile the EA game scripts
Adapted from jcgurango at ModTheSims http://www.modthesims.info/showthread.php?t=533337
1. Create a folder
2. Copy the .zip files in the game's "Data\Simulation\Gameplay\" folder into the folder, and extract each of them into their own folders. You should now have three sub folders, one called "base," "core," and "simulation".
3. Place the unpyc3.py into the folder.
4. Also place a .bat file with the following contents:
Code:
@echo off
for /r %%i in (*) do unpyc3.py "%%i" > %%i.py
pause
5. Also place a .bat file with the following
Code:
REM Batch file for getting rid of the original .pyos and renaming .pyo.py to just .py
for /r . %%i in (*.pyo) do del "%%i"
for /r . %%i in (*.pyo.py) do ren "%%i" "%%~ni"
for /r . %%i in (*.pyo) do ren "%%i" "%%~ni.py"
pause
6. Run the first .bat file. You'll see some errors, but that's okay.
7. Then run the second .bat file.
========================================================
To compile your script
Credit to Lynire at ModTheSims http://modthesims.info/showthread.php?p=4866348#post4866348
After you get your .py file, in order to get it to work you need to make a .pyo file and put that along with your .py file into a zip file. The zip file is what goes into your Sims 4 Mods folder. To make a .pyo file, you can create a batch file named something like PythonOptimizeCompile.bat and put this in it:
Code:
@echo off
if %1x==x goto usage
%~d1
cd "%~p1"
echo on
python -O -c "import py_compile;py_compile.compile('%~n1%~x1','%~n1.pyo')"
@echo off
goto end
:usage
echo drag+drop the .py file onto this to compile to a .pyo file.
:end
pause
If you have more than one Python version installed and the version found by your path is not the version used by Sims 4 (3.3.5) then you will need to put the full path in for the python command rather than just "python" or change your path variable.
Then when you drag+drop your .py file onto that batch file it will create a .pyo file with the same base name as the .py file in the same folder, provided python is in your path. This applies to Windows.
=========================================================
Where to put your scripts so they will run
You can EITHER put the uncompiled .py in Mods/YourMod/Scripts OR you can zip the compiled .pyo into a zip file which you can optionally rename from .zip to .ts4script and this goes into Mods/Scriptmods or wherever else your other downloaded script mods are successfully running from.
========================================================
Making a pycharm project
Start a project
Get all subfolders and loose files out of core, simulation and base and put them in your project root
Mark all folders as source folders.
Add source folders to python path under Console in settings
Do File|Invalidate caches then the red wigglies will go