Python scripting - Include a seperate script?

6c301c866bd83b07323e88a609231111
0
cypher543 101 Sep 20, 2006 at 23:23

I’m currently working on a game engine which uses Python as it’s scripting language. It uses an embedded Python interpreter so that that the engine can have more control over it. Anyway, I used to know Python quite well, but it’s been a few years and I’ve forgotten most of it. Here’s my problem…

The games created with the engine will have different directories for different scripts. For example, AI scripts will be in a “logic” directory, scripts which control map triggers will be in “/maps/mapname/scripts”, and so on.

With Python’s “import” function, I see no way to include a Python script from another directory. It also looks like each script must have a unique name. This isn’t very good for what we want to do.

The only other solution I see is interfacing an “include()” function into Python from the game engine, which loads the new script’s functions and classes into the interpreter and accesses them when called from the original script. This seems a bit complicated, and with so many engines already using Python for scripting, there must be another way to do it.

Any ideas? Should I just use Ruby or Lua instead?

3 Replies

Please log in or register to post a reply.

81c280e6287b230f01c5a42a954f36b2
0
stodge 101 Sep 20, 2006 at 23:31

from DirOne.DirTwo.DirThree import *

?

6c301c866bd83b07323e88a609231111
0
cypher543 101 Sep 20, 2006 at 23:40

Ah… yes. That was actually simpler than I had expected. :p

81c280e6287b230f01c5a42a954f36b2
0
stodge 101 Sep 21, 2006 at 21:54

That’s one of the beauties of Python! :yes: