Author Topic: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts  (Read 7401 times)

Offline cnotsch

  • Posts: 85
  • Cookies: 3
I tryed to use nt.listdir(***) for "scripts/systems/" but it seems like there is no access because it says "Value Error: not allowed" any idea how to solve this?

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #1 on: May 22, 2008, 01:59:55 PM »
Read/Write/List through file access is only allowed on scripts/Custom/ and subdirectories.



You either take all the systems from Foundation (every Systems mod needs to .
Or you have to iterate through them using the Load Save Games "screen". But you can't read nor write to them (reading is possible through some "magic" though).


But it largely depends on what you want to do.


As for the load dialog way:
Code: [Select]
pLoadDialog=App.STLoadDialog_Create(0,0)
pFileMenu = pLoadDialog.GetFileMenu()
pFileMenu.SetFilter("*.*")
pFileMenu.SetDir("data\\Models\\Characters\\" + sName)
pLoadDialog.RefreshFileList()
After that, each child of pFileMenu is a file/directory (including .. and . if I remember correctly).
To read the name you will have to do:
Code: [Select]
pName = App.TGString()
App.STButton_Cast(pChild).GetName(pName)
pName.GetCString()
pName.GetCString() will return the Python usable string.
pChild is a child of pFileMenu (pFileMenu.GetNthChild(#)).
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #2 on: May 22, 2008, 02:17:15 PM »
i just had the idea to replace the sytem config in LoadNanoFX.py with one that does that automatically:
Code: [Select]
def NFXCreateSystemMenues(Directory):
FileList = []
list = nt.listdir(Directory)
for item in list:
s = string.split(item, '.')
sExtension = s[-1]
if sExtension != "py" and sExtension != "pyc":
nDir = string.join(s, '.')
nDir = Directory + nDir
try:
sublist = nt.listdir(string.replace(nDir, '.', '/'))
for subitem in sublist:
subs = string.split(subitem, '.')
subsExtension = subs[-1]
subsPluginName = string.join(subs[:-1], '.')
if subsPluginName != "__init__" and subsExtension == "py":
plugin = string.replace(nDir, '/', '.') + '.' + subsPluginName
module = __import__(plugin)
try:
module.CreateMenus()
except:
pass

except:
pass

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #3 on: May 22, 2008, 02:20:35 PM »
JWattsjr and I both, independantly, once created something like that (I believe lost somewhere). It's not hard, there are just 2 edge cases (the Drydock and Starbase 12 systems).

Foundation.systemList ought to get you underway. ;)
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #4 on: May 22, 2008, 05:52:16 PM »
Yeah but not all systems are listed on the foundation.SystemDefs list. Plus it doesn't contain the real path to the script. Thats one of the reasons I've made the system plugins for Galaxy Charts.

But here's something you can use:  (just a real small and fast test I made in the console and copied the text from the console dump =P)
Code: [Select]
import Systems
####

####
print Systems.__dict__.keys()
['SmokeRing', 'Calufrax', 'Earth', 'Ross_128', 'TheGalaxy', 'Betelgeuse', 'Vesuvi', 'Cebalrai', 'Starbase12', 'Romulus', 'Junkyard', 'Serris', 'Ona', 'Utils', 'Riha', 'Vger', 'Obstacles', 'CJones', 'SystemJ25', 'Tathis', 'Arcturus', 'Pleides', 'Cardassia', 'Biranu', 'Vatris', 'Albirea', 'Nursery', 'Alioth', '__name__', 'Borealis', 'KavisAlpha', 'Voltair', 'Itari', 'DeepSpace9', 'Ascella', 'Prendel', 'ArenaA', 'Baqis', 'Badlands', 'Universe', 'Poseidon', 'PsiBlackhole', 'OmegaDraconis', '__doc__', 'Beol', 'Kastra', 'Comet', 'Kronos', 'Vulcan', 'Procyon', 'BeyondTheGalaxy', 'Void', 'Fluid', 'QuickBattle', 'XiEntrades', 'Belaruz', 'Yiles', 'Sol', '__builtins__', 'String', 'DeepSpace', 'Sirius_B', 'DryDock', 'Khan', 'GasGiant', 'Nepenthe', 'BriarPatch', 'Tezle', 'GammaQuadrant', 'Artrus', '__path__', 'Tevron', 'Banzai', 'Geble', 'RedGiant', 'Chambana', 'Wolf359', 'ShakedownCruise', '__file__', 'Hekaras', 'GalaxyEdge', 'Canopus', 'Savoy', 'Rainbow', 'FoundationUtils']
####

####
print Systems.__dict__['Calufrax'].__dict__.keys()
['__path__', '__doc__', 'Calufrax3', '__file__', '__name__', '__builtins__']
####

####
print Systems.__dict__['Belaruz'].__dict__.keys()
['__path__', '__doc__', 'Belaruz4', '__file__', '__name__', '__builtins__']
####

####
print Systems.__dict__['Belaruz'].__dict__['Belaruz4'].__dict__.keys()
['GetSetName', '__doc__', 'Terminate', 'App', '__name__', 'Initialize', '__file__', '__builtins__', 'LoadPlacements', 'GetSet', 'LoadBackdrops']
That way you can go looping thru each script and each of it's variables, and if they have "CreateMenus", use them.
Problem is, i think python only starts listing the scripts in the __dict__ of the parent directory when they have been initialized.

Dunno if this can really help out or not since i'm kinda in a hurry here, but at least it's something to think about.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #5 on: May 22, 2008, 06:01:38 PM »
It doesn't even have to list them. And it will only list them after you have imported them.


True, the systemList elements don't list those information directly, what they do is (at the very least) provide a convention.
If you prepend the name with "System." then you can import it.
Also, the number of systems (min/max) also tell you the the range of numbers you can expect to be there.

It's not as if QuickBattle can do anything but adhere to this convention anyway (please don't break it).

Say, you want to import the second Serris set, well, it's name is Serris, so System.Serris. then you want the second one, so you __import__("System.Serris.Serris2")
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #6 on: May 23, 2008, 06:41:49 AM »
Thanks I'll try that out sometime soon but I got many things to do for school the next time so it may take some time till I continue my projects  :x :x :x

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #7 on: May 23, 2008, 01:25:14 PM »
USS Frontier, interrested in continueing the discussion of the better System format? ;P
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #8 on: May 24, 2008, 03:23:03 AM »
Of course! A friendly and constructive discussion is always welcomed. That's how ideas are born and problems are solved =P   (or at least one of the ways to do that)

But i'll reply about it tomorrow... It's really late here and I want to go to the bed :P

EDIT:
Personally I think the system plugins (along with GC) are a better format (that's kinda obvious right :P). They are much more flexible/dynamic than the SystemDefs and can contain a LOT more info about the systems. And with the plugin creation tool they aren't hard to make.
Plus they are used for a bunch of stuff, while the SystemDefs are there only to add the systems to the QuickBattleSetup System List.
And using the QB setup to create a battle simulation is something that with KM1+GC is kinda useless, since when you just started the QB mode (didn't setup a battle yet), you can already warp with no problems to anywhere, and using AddShips you can add the ships you want in the group that you want.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #9 on: May 25, 2008, 05:17:35 AM »
i know, it was just a idea out of lazyness to let a script automatically load new installed ships, so don't get too busy with finding a way to do this.

I'm currently trying to port the SP - missions into QB and I succesfully portet the first Episode already, but I got to a problem in E2M0: When creating a WarpAI with no set and no placement the ship turns into a direction to warp but then simply stays there and does nothing. when loading the "Zhukov" with loadspacehelper.createship with the set as well as her starting nav-point set, the game crashes, it works when leaving the nav-point name clear

Code: [Select]
loadspacehelper.CreateShip("Ambassador", pSet, "Zhukov", "", 1)
Any Ideas?

If letting her warp to Starbase12 with the sovereign the sovereign stays there and the zhukov returns to me and follows me everywhere i warp. setting a new AI after arriving in Sb12 changes nothing, so i tried assigning the AI manual to a manually created zhukov (manually -> i mean by console) and it works ???
i solved thisone by destroying her when she enters Sb12  :lol:

Any better Ideas?

NOTE: I use GalaxyCharts

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #10 on: May 25, 2008, 06:58:57 AM »
Any newly installed ships will already be known to BC through Foundation.shipList


As for the navpoints, lots of missions declare mission only navpoints or even a custom placements for a system, look in the mission directory for <<systemName>>_P.py for their custom placements.


Also, did you know that QB is just another mission of itself?
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #11 on: May 25, 2008, 09:28:38 AM »
Also, did you know that QB is just another mission of itself?

Shure this is exactly my intention. Look, If I'd try to make every mod I like SP-compatible i woult take years and there are coming more and more so why not trasform SP int o plugin for QB?
Doing so I reach nearly the same mod compatibility in SP as in QB - and I have the work only once...

As for the navpoints, lots of missions declare mission only navpoints or even a custom placements for a system, look in the mission directory for <<systemName>>_P.py for their custom placements.

I know that is what i thaught first too : There is no such navpoint;
BUT, they are there I'm sure and exactly that seems to be the problem. It also works when I set the placementname to "hithisisblabla" - thats the weird thing.

In the meantime I got an Idea for the WarpOut AIs: A sequence tha does the following:
1. PlainAI-RunScript:               Create the Set "DeepSpace" if it does not exist yet      - works
2. PlainAI-Warp:                     Warp to "DeepSpace"                                              - works, i think
3.(version1) PlainAI-RunScript: pShip.SetDeleteMe(1)                                              - does its job the ship dissapears, BEFORE warping
3.(version2) ConditionalInSet:  with the parameters: pShip.GetName(), "DeepSpace" and 3.(version1) as child;  - results in an instant crash of stbc.exe  :? :? :?

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #12 on: May 25, 2008, 09:46:07 AM »
I'm not well versed in BC AI code, so I can't really help you there.


As for your E2M0 issue, if a ship warps to no destination, then it ought to warp out and then be removed (deleted). Maybe Galaxy Charts didn't replicate this?

And the Tevron System does have a ZhukovStart navpoint, atleast in the mission specific placements file.
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #13 on: May 25, 2008, 11:47:58 AM »
Quote
There is no such navpoint
sorry i may have not been clear enougth there; This should be my idea but if you are looking into the next line i wrote that they are there;
I wanted to say i can use any navpointname exept the existing ones  :? :? :? -> it HAS to be an invalid navpoint...

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #14 on: May 25, 2008, 12:00:46 PM »
Quote
There is no such navpoint
Yes, I thought that was what I read....


Now you read.

I must be blind having read that it says ZhukovStart. -_-
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline Mark

  • Retired Administrator
  • Posts: 1930
  • Cookies: 1797
  • Site Co-Founder
    • ST Excalibur
Re: access to directory (nt.listdir(***))
« Reply #15 on: May 25, 2008, 05:03:37 PM »
ok guys, lets stay focused on the problem at hand..

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #16 on: May 25, 2008, 07:44:39 PM »
sorry there mark, but i want to sort that out i don't want to make anyone angry here!

From my side it was like that:
I wrote my scripts the i got to that weird crashing thing with the zhukov.
Then i THAUGHT there might be no navpoint and for that reason the game crashes.
So i checked this about 10 times everytime with the result there must be a navpoint.
Next i tried setting the placement name to something else wich does not exist.

So i posted that.
Quote
I know that is what i thaught first too : There is no such navpoint;
BUT, they are there I'm sure and exactly that seems to be the problem. It also works when I set the placementname to "hithisisblabla" - thats the weird thing.

Now you told me:
Quote
And the Tevron System does have a ZhukovStart navpoint, atleast in the mission specific placements file.

So i thaught you understood my post as "i still think there is no navpoint" and i wanted to be shure you understood me...

see the problem? i hope you aren't mad  :(

I'm really grateful for your help don't get that wrong.

besides that it was a nice idea with that pic  :lol:


Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #17 on: May 25, 2008, 11:32:09 PM »
The <Ship warping to NONE and being left at the set (that is, not being removed)> is a known bug in GC and has already been fixed in the upcoming patch.

Also GC checks and creates the destination set if it needs, so there is no need for you to do that =P


Now about the placement/navpoint thing I won't say anything because personally I didn't understand what you said  :?
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #18 on: May 26, 2008, 12:29:14 AM »
Quote
The <Ship warping to NONE and being left at the set (that is, not being removed)> is a known bug in GC and has already been fixed in the upcoming patch.
good to hear. there is also the problem that when entering a set after warp you drop out of warp ~1000km from the center planet - did you consider to fix that too?
so lets say the ship enters as near as possible to "Player Start"?
that would make my work a lot easier.

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #19 on: May 26, 2008, 06:56:08 PM »
there is also the problem that when entering a set after warp you drop out of warp ~1000km from the center planet - did you consider to fix that too?
so lets say the ship enters as near as possible to "Player Start"?
that would make my work a lot easier.
Actually I didn't consider that =P
But it can be arranged as well. I'll see what I can do.

But for the moment, here's something you can do to easily change the location where the player drops out of warp:
Code: [Select]
pPlayer = App.Game_GetCurrentPlayer()
vPosition =  **the point in space (App.TGPoint3 obj) where you want the player to drop out**
pTravel = App.g_kTravelManager.GetTravel(pPlayer)
if pTravel != None:
pTravel.SetExitLocationVector(vPosition)
If that position is empty, the player will drop out of travel there. If there is some kind of obstacle there, GC will pick up a new exit position close to that one that is free.
Note that this code will only work if GC is installed, since the Travel Manager is from GC.

Also in your version of GC (v1.0, because in the patch this aspect is changed), the Travel instance of the player will only be created when he tries to travel. So the best thing to do is listen for a START_WARP_NOTIFY event, and if it's from the player, use the code in the example above to change his exit location.
OR instead of using that "GetTravel" method you can use "CreateTravel", to create the player's travel instance, and then set his exit location. Don't worry doing this since it won't cause any problems, and the exit location will be stored until the player exits warp and uses it  (that is if nothing else changes it. I don't remember exactly but I think some AIs change the exit location, that's why I gave the example of the START_WARP_NOTIFY event, since at that point probably nothing will change that attribute)
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download