Data Structures, Module imports *solved*

Hi folks,

i had to do a hacky workaround to change the backgroundcolor in realtime, because i didnt know, that now it really works… nice! (bge.render.setBackgroundColor([R,G,B,?)], since18.2.11)

this thread:
http://blenderartists.org/forum/showthread.php?t=209239

Now i want to use newest Verions to use this new feature, because i will stuck with this ‘old’ Version…

In my actual build(34959), or better, in all versions i tried after 2.56.0 (34074), the data structure doesnt work anymore; all imports from other script dont work…

I made a simple Test-Environment, and tried it on Windows 7, Ubuntu 9.x and 10.10.

Here are the Codes:

-This sets all Pathes:


################################################################################
#
# Copyright (C) 2010, Martin Sell <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
################################################################################


''' 
Descr... Module
==============================

Detailed descr...
'''

__version__ = "0.0"
__author__ = "Moerdn"
__package__ = "Src"

import os
from os import path
import bge
GL = bge.logic
sep = path.sep

#from .SrcInterfaces.IFunctions import *


def findSourceDir(folder):

    for pathentry in os.walk(folder, True):
        if 'Src' in pathentry[0]:
            return True
        
    return False


def getLibraryPath():


    fd = '//'
    folder = GL.expandPath(fd)
    
    while not findSourceDir(folder):
        fd += '..' + os.path.sep
        folder = GL.expandPath(fd)

    LIBRARY_PATH = [folder + 'Src' + sep,
                    folder + 'Src' + sep + 'ModFunc',
                    folder + 'Src' + sep + 'config',  
                    folder + 'Src' + sep + 'Testfunc'
                    ]

    print(folder)

    return LIBRARY_PATH


def printLibraryPath():
    pass

-This Initialises the Pathes in GameEngine, gets all Source Locations:



################################################################################
#
# Copyright (C) 2010, Martin Sell <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
################################################################################


''' 
Descr... Module
==============================

Detailed descr...
'''

__version__ = "0.0"
__author__  = "Moerdn"
__package__ = "Src"


#from .SrcInterfaces.IFunctions import *
#from .SrcInterfaces.IGameLogic import *
from . import __config__
import bge
GL = bge.logic



def init(con):

    """ Init all Source Locations """


    if con.sensors[0].positive:

        ##
        #  @descr: Append all Source Pathes to the System LibPath 
        #
        from sys import path
        
        for PATH in __config__.getLibraryPath():
            path.append(GL.expandPath(PATH))


    ##
    #  @descr: Run whatever actuator meant to be runned
    #
    for sen in con.sensors:
        if sen.positive:         
            for act in con.actuators:
                con.activate(act)


def cleanup(con):

    """ Cleanup all pyc Files """

    import os
    
    for pathentry in os.walk('Src', False):
        
        for py_file in pathentry[2]:    
            split_file = py_file.split('.')
            
            if len(split_file) is 2:
                if split_file[1] == 'pyc':
                    
                    path = os.path.join(pathentry[0], py_file)
                    os.unlink(path)

I dont know where to start debug, because it worked perfect, i have no idea…

Maybe someone has the same or similar problem and know a solution…

here are the Test files:

http://npshare.de/files/bfc79ca5/expandPath.zip

Thanks for your interest.

Edit:

after several hours of brain burning researches, i finally find out that i simply had to include the folders name into the import:
instead of :

from .module import function

one has to write:


from folder.module import function

Another thing that worked perfect since now was:


from GUI.GUI.import GUI # folder.module import function

but now, one has to give specific names, the same names for folders, Scripts and function doesnt work anymore… it is anyway very bad style…

So i’m very happy to be able to go on…:spin:

Because not even the cracks in this forum had any ideas for that issue, i dont think this thread has any relevance to others.
If anybody, need help dooing this, feel free to contact me… i still have a working Tutorial file for 2.56.x .

Thanks to moerdn for not helping me(seriuos!!), i learn a lot doing it myself :smiley:

@ moerdn:

is there a thread about this system in the Game Engine Ressources?
If not, why not post one there?

Otherwise i will probably post a short Tutorial there, but, i’m still not experienced enough to fully understand it, much less to explain it.

To the admins:

Feel free to delete this thread, if you think it is useless, or contact me to put it in the Game Engine Ressources.

Thanks