Python to Funky Trees Mini Compiler
PYtoFT converts variables in a Python script into condensed, single-line functions compatible with the SimplePlanes / SimplePlanes2 Funky Trees system.
The tool can:
- Automatically update the .xml file of a SimplePlanes craft, or
- Update the .xml file next to your .py script, or
- Output the generated XML code directly to the console for copy-paste use.
Caution
- It is not recommended to use this tool unless you are familiar with the basics of Python and how Funky Trees work in SimplePlanes.
- Incorrectly written Python code may result in conversion errors or unexpected in-game behavior. Use this tool at your own risk.
- Parses variable definitions from a Python script using ast module.
- Converts them into SimplePlanes-compatible Funky Trees expressions.
- Outputs the result as XML code, either by injecting it into an existing craft file or printing it for manual use.
- Go to the Releases section and download the .zip file.
- Unzip the downloaded archive.
- Run PY_to_FT_GUI.exe and choose your python script and the output XML file.
- Click "Convert" button to start conversion.
- If you didn't choose the XML file, the output will be shown in the text box for copy-paste use.
- You may need to reload your aircraft in game to see your Funky Trees code changes.
-
Install Python 3 and download or clone this project
-
Run (CLI / GUI):
python _PY_to_FT.py
or
python _PY_to_FT_GUI.py
Full working demo script: demo script
Demo airplane XML: Pyphoon demo plane
- The Python script must have the same name as the target SimplePlanes .xml craft file.
- Do not start your file name with an underscore.
from lib.FT_functions import * # import built-in Funky Trees functions and variables.
main_loop_name = "_process" # the name of the main function
exclude = ["exported_var"] # list of variable names to be excluded from the conversion,
# you may need to add some aircraft-part-exported variables here.
# ========== program start ==========
# optional: declare your global variables
my_global_var = 1.0
exported_var = False
# main loop function: the control logic in this function will be executed once every frame in game.
# all variables declared inside this function + all global variables will be converted to in-game variables.
# you can also do not write this function, then only global variables will be converted.
def _process() -> None:
global my_global_var
global exported_var
simple_var = 2000.0
if my_global_var:
if IAS > exported_var:
another_simple_var = foo(simple_var)
else:
another_simple_var = 0
else:
another_simple_var = -1
# below are helper functions, make sure all functions have return values in all cases.
# it's not recommended to call other helper functions inside helper functions.
# do *NOT* use recursion!
def foo(some_value) -> float:
input_val = some_value
if Altitude > 200:
input_val += 2
else:
input_val -=2
result = input_val + bar()
return result
def bar() -> float:
if IAS > 10:
return 5
else:
return 0The script above can be converted to the following XML code:
<Setter variable="my_global_var" function="1.0" priority="0" />
<Setter variable="simple_var" function="2000.0" priority="0" />
<Setter variable="another_simple_var" function="(my_global_var ? ((IAS > exported_var) ? (((Altitude > 200) ? (simple_var + 2) : (simple_var - 2)) + ((IAS > 10) ? 5 : 0)) : 0) : -1)" priority="0" />Note
This tool can only convert simple functions. The following Python features are not currently supported:
- Classes
- Recursion
If you want to reconfigure the directory of your target output folder, you can delete _PY_to_FT_config.json and run the application again.
Caution
Always backup your .xml craft file before running the conversion.
The conversion will overwrite ALL Funky Trees codes you have already written in game in Variable Setters.
I hope you find this tool useful. In the future, it would be interesting to support the conversion of other popular languages (such as C#, Java, or JavaScript) into Funky Trees; however, this is currently beyond the scope of my skills.
I may also pursue future updates to expand support for additional Python features.
If you find this work useful, any amount of support would be appreciated: Patreon
This project is licensed under the GNU General Public License v3.0 (GPL-3.0-or-later).
