Skip to content

Examples and your mod development

Lukasz Taczuk edited this page Dec 1, 2024 · 3 revisions

Testing if it works

Run Arma 3 with -mod=@Pythia.

In SQF (debug console), execute:

["pythia.test"] call py3_fnc_callExtension

This should reply with a OK hint message, if Pythia is working correctly. If it doesn't, ensure you've disabled BattlEye.

["pythia.ping", ["first", "second", 3]] call py3_fnc_callExtension

This should echo back all the arguments you're passing to the function.

Running your own code

  1. Open the directory of your Arma mod (Pythia assumes you have a mod, because you need to have a place to call the SQF from, anyway).

  2. Create a directory that will hold your python code; its name doesn't really matter, but let's name it python_code for this example.

  3. Create a python_code\$PYTHIA$ file and put your module name inside. Again, let's assume samplemodule as the file contents, for this example.

  4. Create a python_code\__init__.py file and put your code there. This works as a regular python package so you can also add other files there, your can import them, etc...

  5. Run Arma with -mod=@Pythia;@MyAwesomeModule (or you can just enable them in the launcher, instead)

  6. Call your python code from the debug console, by typing:

["samplemodule.sample_function", ["first", "second", 3]] call py3_fnc_callExtension)

This will open the directory @MyAwesomeModule\python_code\, load the package there, by loading __init__.py, and internally name it samplemodule, call the python function sample_function("first", "second", 3) and return the value returned by that function to SQF.

To sum up, this is how your directory structure should look like:

@MyAwesomeMod/
├── Addons/  # (...)
└── python_code/  # Can be named however you want; you can have more than one
    ├── $PYTHIA$  # Contains the name of your python package, for example: samplemodule
    └── __init__.py  # Contains the function called (or imports other files)

Examples:

In __init__.py:

def print_args(*args):
    return_string = 'Received args: {}'.format(args)
    return return_string

In SQF:

["samplemodule.print_args", ["First", "Second", 3]] call py3_fnc_callExtension

Result: "Received args: ('First', 'Second', 3)"


In __init__.py:

def get_multiples(multiplier, count):
    return [i * multiplier for i in range(count)]

In SQF:

["samplemodule.get_multiples", [3, 6]] call py3_fnc_callExtension

Result: [0, 3, 6, 9, 12, 15]

Additional examples

You can access additional and more up to date examples here: https://github.com/overfl0/Pythia/tree/next/examples

Clone this wiki locally