File path issue

It was CyGame().getReplayInfo().getModName() but it didn't work. It apparently produced an empty string. :rolleyes:

Why don't I use your code? Because I don't have the CvModFolder module and I'd rather not include either. But I guess I can find the code that actually works in there, then?

edit: No such luck. I can't find the CvModFolder module in \BUG Mod 4.3\Assets\Python\ or any of its sub-folders. Where are you importing it from then?
 
This doesn't work either:
Code:
replay = CyReplayInfo()
replay.createInfo(0)
modName = replay.getModName()
It still produces an empty string. :p
 
CvModFolder is only there in case the replay thing doesn't work for some reason. I've never had it fail. Are you trying that with an actual mod loaded?
 
Yeah, its a mod-mod based on RFC. The mod folder is called RFCMarathon. This is the whole thing:
Code:
        def script(self):
                execfile(self.path())
                
        def path(self):
                if not isValid(self.mapPath):
                        replay = CyReplayInfo()
                        replay.createInfo(0)
                        modName = replay.getModName()
                        self.mapPath = "Mods\\" + modName + "\\Assets\\Python\\Scenario.py"
                return self.mapPath
self.mapPath is set as "" on init and isValid() is probably my most used helper function:
Spoiler :
Code:
def isValid(value):
        return value != None and value != -1 and value != ""
It throws this exception:
Spoiler :
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 13, in ?
File "<string>", line 52, in load_module
File "CvRFCEventManager", line 6, in ?
File "<string>", line 52, in load_module
File "CvRFCEventHandler", line 168, in ?
File "PyScenario", line 70, in rebuild
File "PyScenario", line 55, in build
File "PyScenario", line 66, in script
IOError
:
[Errno 2] No such file or directory: 'Mods\\\\Assets\\Python\\Scenario.py'

I interpret this as the getModName() method returns an empty string.

edit: My temporary solution is to enable the user to set the mod name manually, and it works:
Code:
modName = "RFCMarathon"
...
        def script(self):
                execfile("Mods\\" + modName + "\Assets\Python\Scenario.py")
 
Notice that BugPath puts the above code into a try block with a catch clause that logs a message saying that the replay isn't ready. When is your code running, because it cannot be before "the right time." This is one of the main issues I had to tackle when first writing BUG. Some game objects are not ready until the GameStart or OnLoad event is fired.

This is precisely why using BUG is so helpful for some modders: it takes care of all this crap for you. You can register a function to be called during "init" time that BUG will call at the correct time whether the user is loading a game or starting a new game. I know you're using RFC and so BUG isn't an option. Check out BugInit and BugEventManager for some details, but it's not pretty.
 
Yeah, I've encountered a lot of these issues with CyGame also, and believe that I fully understand what you're saying. But I was testing this with the game already in progress, and never even got to the part where I had to figure out what to do before the game is properly initialized and whatnot.
 
Ok, I tried the code in the console and got the string:
"Mods\RFCMarathon\"
But when I run the script it doesn't seem to register. I'll investigate further...
 
Ok, now its working. I tested it with a couple of games, both on init and reloading during play. I guess I'll have to test it with another computer also. (This is where my previous attempt failed - the path wasn't registering on someone else's computer.)
Code:
        def path(self):
                if not isValid(self.mapPath):
                        replay = CyReplayInfo()
                        replay.createInfo(0)
                        modName = replay.getModName()
                        self.mapPath = modName + "\\Assets\\Python\\Scenario.py"
                return self.mapPath
I'm not sure what made it work, all of a sudden, and its somewhat uncomfortable not to know what the problem was. :p
 
Back
Top Bottom