Python Scripting

Adonthell makes use of Python (http://www.python.org) as a scripting language. Small modules of Python code are used to controll game elements like mapcharacters, mapviews and events or to perform special tasks like animated cutscenes, etc..

Why use a scripting language?

There is an important difference between game engine and game data. Adonthell's goal is the ability to run different games without any modification to the actual game engine. This requires that games using the Adonthell engine can be created without writing a single line of C++ code.

Most game data (maps, characters, etc...) can be easily created with the help of the respective editor. But some elements need to be controlled by a program. For example, Non-Player Characters (NPC's) or mapviews. Rather than having a limited set of behaviors in the engine, it's better to directly program them using a easy to use, platform independant, interpreted language. And that is where Python comes in. Using Python, you can easily create your own behavior scripts (also called schedules) for the characters, as well as other parts of the game (cutscenes, etc...). Actually, the entire C++ API is available from Python - so when you create Python scripts you have exactly the same possibilities you would have when writting them in C++.

Using Python with Adonthell

The complete Adonthell API is available through the adonthell module, which is imported at startup. There is a little customized Python interpreter in src/tools/pydonthell/ you can use for testing purposes: go into a valid game directory, run pydonthell from here and try this little example program:

>>> from adonthell import *
>>> im = image ()
>>> im.resize (100, 100)
>>> im.fillrect_rgb (0, 0, im.length (), im.height (), 255, 0, 0)
>>> im.draw (10, 10)
>>> screen_show ()

All the classes and methods used in this little script are explained in the API reference.

Python scripts

The py_object class is designed to handle most of the Python scripting. It imports a Python module which should only contain Python classes. An instance of the selected class is created and you can freely call it's methods. See the py_object class reference for more details concerning it's use.

Generated on Sun Mar 1 09:57:02 2009 for Adonthell by  doxygen 1.5.8