Scripting in Python

brine edited this page Mar 20, 2018 · 1 revision

It is possible to directly interact with game elements from scripts written in Python.

See also

Limitations

Such scripts execute in a secure sand-box environment. Because of that it's impossible to access any resource such as a file on disk or the network. The only thing allowed is for the scripts written to drive OCTGN's behavior.

About Python

Python is an excellent scripting language. If you don't know it, you can start with this interactive tutorial (you need Silverlight): http://www.trypython.org or this more complete tutorial: http://docs.python.org/tutorial/

The best reference about Python is http://docs.python.org/index.html, especially the language reference: http://docs.python.org/index.html and the library reference: http://docs.python.org/library/index.html

Please note that the version of Python embedded inside OCTGN is mostly 2.7 with some additions coming from the 3.x branch. In the future OCTGN will most probably switch to a Python 3.2 release, so keep that in mind when writing scripts.

Known Problems

  • As of OCTGN 0.9, because of the security of its sandbox environment, many errors can't be passed from the Python environment to OCTGN's main program. This has no impact on correct programs but sometimes makes debugging Python code painful.
  • As of OCTGN 0.9, the Python scripts do not enforce controller-ship on the object that they manipulate. It is not safe to change the state of cards or groups you don't control, even though the script would let you do that.

The only functions that are safe to use on elements you don't control are target, highlight, as well as counter and marker manipulations. Of course you can still read the state of any element.

So be very careful to always filter the cards you touch. Always write code which will catch such errors / mishaps as below.

DO NOT use (c for c in table); DO use (c for c in table if c.controller == me).

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.