Phython as In-Game scripting language

Nick Trout nick at spam_me_notvideosystem.co.uk
Wed Feb 23 13:21:54 EST 2000


> Being totally new to Python and completely honest in saying that
> I have no idea of what I'm doing, I had a few questions.

Follow the tutorial, its easy and very good. Get some modules from
www.python.org and look at the code. There are some very clever people out
there.

> My team and I are thinking about embedding Python into our
> game engine on the Windows platform. The basic idea would be that the
> major entities, including enemies, would have a script attached to
> them to control behavior. This would allow the level/content designers
> to concentrate more on the game design side of things, since
> behaviors would be outside of the main game engine. Is it
> possible to have multiple scripts running at the same time?
> Would this involve creating multiple interpreter objects? According
> to the docs, this is possible but it isn't totally safe to do.
> What would be a good strategy for this?

Personally I wouldnt try and run multiple scripts. You could have an object base
class for common functionality and properties (eg. position and orientation)
which has a method tick(). All your game characters inherit from this and get
updated once a frame by a scheduler which you have written. You have one Python
state which all you scripts reside in.

You could take the whole thing to the extent of writing the game code as a
Python extension and controlling the whole thing from Python! eg. python script
sets up game, frame loop consists of update characters and then call renderer.

> My other question was one of performance. Is it crazy to have
> ~10 different objects with each an individual script and hoping
> the game will be running at 30 frames per second? The question might not be
> valid, since I'm not sure how to implement it in the first
> place.

I dont think its crazy if you have fairly simple behaviour. An alternative
language you might want to look at which is supposed to be quicker is Lua. Grim
Fandango and supposedly Balders Gate use Lua amongst others. Its designed to be
embedded. If I remember correctly someone has written a multistate/threading
version of Python specifcally for writing games software.

> And lastly, is it faster to call C functions in Python or vice-versa?

Not sure this is relevant. All your time consuming code should be done in C.
e.g.. collision, path calculation and called from Python.








More information about the Python-list mailing list