You are not logged in.

#1 2005-08-20 14:21:55

deficite
Member
From: Augusta, GA
Registered: 2005-06-02
Posts: 693

Python scripting from within python

I have been designing a game to sort of break me into python a bit and I have been considering one thing: scripting. I need scripting for game events, etc. I was just wondering what you guys thought the best way of doing this is? I want to allow map makers to ship all the scripting they need for their maps in plain python files that can be included in their tarball (I am using tarballs to store maps and all their unique resources)

The only thing I really need advice on is loading the scripts.

Offline

#2 2005-08-20 17:08:51

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: Python scripting from within python

for importing source you can do like this:

_file = open(os.environ['HOME'] + "/.config/my_game/my_script", "r")
my_script = imp.load_source("", os.environ['HOME'] + "/tmp/my_game.swap", _file)
_file.close()

i haven't figured out yet how to make it load the source "without" saving a file as bytecode (it's the .swap file), if anyone else knows please say so, smile


arch + gentoo + initng + python = enlisy

Offline

#3 2005-08-20 18:48:33

deficite
Member
From: Augusta, GA
Registered: 2005-06-02
Posts: 693

Re: Python scripting from within python

Thanks! I tried searching google for this but you can imagine how many nonrelevent results I was getting.

Offline

Board footer

Powered by FluxBB