Bridge Commander Central

BC Forums => BC Scripting => Topic started by: Rob Archer on August 29, 2006, 01:20:48 PM

Title: Attaching the SetName to a directory
Post by: Rob Archer on August 29, 2006, 01:20:48 PM
I know how to get the SetName Using the

pSet.GetName() command

but i want to use it to import the corosponding file from a directory.

Example of what ive tried:

Code: [Select]

        pPlayer = MissionLib.GetPlayer()
pSet = pPlayer.GetContainingSet()
sSetName = pSet.GetName()
print("Current Location: " + str(sSetName))
__import__ ("Custom.QBautostart.NFSystemDirectory." + sSetName)


So it will import  the name of the system i.e Belaruz4 and add it so it will

import Custom.QBautostart.NFSystemDirectory.Belaruz4

Ive had it working with the Print Command but i cant get it to acctually import the file can someone lend a hand.
Title: Attaching the SetName to a directory
Post by: MLeo on August 29, 2006, 02:07:15 PM
For starters, there would need to be a file (or directory with __init__.py in it) called that way in scripts/Custom/QBautostart/NFSystemDirectory.
Title: Re: Attaching the SetName to a directory
Post by: SimRex on August 29, 2006, 02:16:09 PM
Quote from: Rob Archer
I know how to get the SetName Using the

pSet.GetName() command

but i want to use it to import the corosponding file from a directory.

Example of what ive tried:

Code: [Select]

        pPlayer = MissionLib.GetPlayer()
pSet = pPlayer.GetContainingSet()
sSetName = pSet.GetName()
print("Current Location: " + str(sSetName))
__import__ ("Custom.QBautostart.NFSystemDirectory." + sSetName)


So it will import  the name of the system i.e Belaruz4 and add it so it will

import Custom.QBautostart.NFSystemDirectory.Belaruz4

Ive had it working with the Print Command but i cant get it to acctually import the file can someone lend a hand.


I presume you know the __import__ command doesn't work quite like normal importing?

If you're trying to access variables or methods in the imported module, you need to do something like this:

Code: [Select]
mModule = __import__("stuff")
mModule.Whatever()
Title: Attaching the SetName to a directory
Post by: Rob Archer on August 29, 2006, 03:46:22 PM
Thanks Guys

I figured it out in the end anyway and the system seems to be doing what i want

Thanks for the help.