External Python script

Didn’t know if this belongs here or in the bge section, but this is what I’m trying to find out.

I am wanting to use a script saved in my own home directory instead of using blenders text editor. I want to use it in a controller logic brick as a module. I’ve tried putting the path to the script into the logic brick, but that didn’t work.

I’ve also tried putting the directory I want in the user prefs under Python Scripts, but still didn’t work. I googled around, maybe not enough, but everything I find is about executing external scripts. I don’t want to execute it, but have the logic controller hook it and use it from there.

Have you tried this one? Putting scripts here let’s you use "import yourmodule in any blender script.
C:\Program Files\Blender Foundation\Blender\2.68\scripts\startup

If you’re on linux/mac you can make a symbolic link from ~/.config/blender/2.69/scripts/startup to where the file/module is.

I did get it to work, well kinda. I put the script directly in the folder containing the .blend file and that works. Now if I make a folder in the same dir and put the script in there, I can’t figure out the syntax for the controller.

I am on Linux, and if I make a sym link wont that mess up if I export the project as a standalone executable and run it on another machine?

Yes, that would mess it up.

I haven’t done much with the game engine, but I suggest using modules.

myblend.blend
mygamestuff/
    __init__.py
    foo.py
    bar.py

in init.py put this

from . import foo, bar

and in your scripts you can do

from mygamestuff import foo
   foo.somethingInFooDotPy()

I figured it out. Turns out there is no way to have a sub directory and call scripts from within it from the logic bricks. It does work when the scripts are in the same directory as the .blend file is in. I could use the module way as suggested by GreenJello, but for now I’ll keep it all in the same dir. Once I get everything going, I might wrap everything up in module form for everyone. But till then, tis solved.