Partial Python error

timike

Chieftain
Joined
Nov 1, 2009
Messages
18
Hey everyone Im rather new to trying to accomplish modding on my own. Ive recently relatively successfuly combined 2 mods (Thomas war 3.5a and Petromod) into one nice package. They only problem ive come up with now is that when you go to build a refinery in your city to is supposed to found a eco-oil fanchaise in the city ( rewritten standard ethanol). In the vanilla petromod this does concure but with the combine I cant get it to happen.

Here is the python code i borrowed from the petromod creator to try and copy the event.

if iBuildingType == CvUtil.findInfoTypeNum
(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_REFINERY"):
icorp = CvUtil.findInfoTypeNum(gc.getCorporationInfo,
gc.getNumCorporationInfos(), "CORPORATION_3")
pCity.setHasCorporation(icorp, 1, 1, 1)

Now if copied the rest of the mod in with success its just this last part im trying to make seamless and make it into a nice combined mod.

If anyone has some insight Id appreciate it.
 
Please use
Code:
 tags when your posting your code, it makes it easier to read.
So what happens when you build the refinery? Have you turned on python exceptions? If not, I highly recommend that. Go to my games/beyond the sword (or something like that) and open your CivilizatioIV.ini. Search for python and you should find this:[CODE]; Set to 1 for no python exception popups
HidePythonExceptions = [COLOR="Red"]1[/COLOR]
Change that number to 0.

Code:
CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_REFINERY")
You can replace that with this
Code:
gc.getInfoTypeForString("BUILDING_REFINERY")
it should be faster.

So turn on you python exceptions, I can't notic anything wrong in your code.
 
thanks ill try it. And right now nothing happens when i build the refinery. I mean it builds completely and the building itself comes about with its set values the only thing its not doing is spreading the franchaise to the city

edit: Well its still a no go on the company spread but i did notice some new evidence of something erroring. originally I tied together these mods using the thomas war mod as a base and adding the petromod xml changes and that python code line. What im seeing now is that after the mod is turned on it creates a petromod.ini and ini.bak file in addition to the thomaswar.ini and bak files that were already in the folder. Ive check and no matter if i remove these files before playing everytime the mod is used it recreates the files
 
well i ran the python exceptions alot of blank things popped up but i did get a exception on the one line of code

if iBuildingType == CvUtil.findInfoTypeNum

I copied this straight from the python in petromod so Im at a loss why is throwing this out
 
well i ran the python exceptions alot of blank things popped up but i did get a exception on the one line of code

if iBuildingType == CvUtil.findInfoTypeNum

I copied this straight from the python in petromod so Im at a loss why is throwing this out

Post your code around that part in
Code:
 tags. It might be easier to find the reason. But it seems that you have some code in wrong places.
 
Alright this is how it is written exactly as is in the python file

Code:
#Petromod
if iBuildingType == CvUtil.findInfoTypeNum
(gc.getBuildingInfo, gc.getNumBuildingInfo(),"BUILDING_REFINERY"):
icorp = CvUtil.findInfoTypeNum(gc.getCorporationInfo, 
	gc.getNumCorporationInfos(), "CORPORATION_3")
pCity.setHasCorporation(icorp, 1, 1, 1)
#Petromod
 
Alright this is how it is written exactly as is in the python file

Code:
#Petromod
if iBuildingType == CvUtil.findInfoTypeNum
(gc.getBuildingInfo, gc.getNumBuildingInfo(),"BUILDING_REFINERY"):
icorp = CvUtil.findInfoTypeNum(gc.getCorporationInfo, 
	gc.getNumCorporationInfos(), "CORPORATION_3")
pCity.setHasCorporation(icorp, 1, 1, 1)
#Petromod

:confused: Was it exactly like that in the mod where you copyed it? I'm not sure if you can place them like that. I'll do some testing and be right back.

EDIT: Okay, now I've tested it. I'm suprised that this code has worked.
Mayby the biggest mistake is the placement of those lines. Python wants the lines to be in their places and prefers tabs instead of spaces.
Also you should replace the CvUtil.findInfoTypeNum(...) with gc.getInfoTypeForString(), my civ had some problems with them.
Code:
		#Petromod
		if iBuildingType == gc.getInfoTypeForString("BUILDING_REFINERY"):
			icorp = gc.getInfoTypeForString("CORPORATION_3")
			pCity.setHasCorporation(icorp, 1, 1, 1)
		#Petromod
This is how atleast it should work.
 
Well that did help slightly I now get 0 python exceptions but the game still refuses to bring in the oil franchaise to the city.

I even went out on edge and copied the CvMainInterface and CvReligionScreen Screens over the thomas war ones that i left alone. This was the last thing out of the petromod to not be moved. Even with these files move it still refused to initiate the corporation.

Im pretty much at a loss to what could possibly be missing.
 
Perhaps I missed part of your motivation. But can't you accomplish founding a corporation when a building is built, by using the <FoundsCorporation> tag in the building xml?

If that isn't what you meant and python is the only solution, I highly recommend you go back to basics. Take an empty mod directory and make only this change, without any of the other mods' code getting in the way. Just modify the onBuildingBuilt function in the vanilla CvEventManager.py and see if this works. There are often unexpected interactions between subcomponents of mods you have incorporated.
 
wouldnt the found corporation tag found the headquarters of the corp not just a franchaise spread?
 
In the OP he asks to "found" a corporation. But, after looking at the code more closely, it does appear to "spread" the corporation. Thanks for the clarification.
 
Well that did help slightly I now get 0 python exceptions but the game still refuses to bring in the oil franchaise to the city.

Hmm, I tested it and managed to spread the corporation to the city. Have you changed the corporation names? I don't know if that would cause some errors but atleast you should check.
 
Hmm, I tested it and managed to spread the corporation to the city. Have you changed the corporation names? I don't know if that would cause some errors but atleast you should check.

What mod did you happen to test this on. The Thomas War?
 
timike, my best guess is that you've managed to replace the XML for the Corp HQ with another set of values. So it wouldn't even be Python related. Try and replace the XML files and see what happens.

NotSoGood said:
Python wants the lines to be in their places and prefers tabs instead of spaces.
Eh, I don't mean to be a nit-picker, but aren't tabs a no-no in Python? I thought it was only kosher to use blank spaces for indentation. :crazyeye:

Why that code worked with those line breaks remains a mystery to me also, but those lines perhaps use another type of line breaks? Otherwise I use backslash (\) for arbitrary line breaks in Python code myself.
 
I created a own mod and added only those 3 (5 with comments) lines, and it worked.
Well ofcourse I had to change the building's name.



So you inserted a different building like a harbor or something and it spread the stock standard ethanol corp? If so this getting annoying why this just wont simply work.

Also I noticed with the vanilla petromod if the mod folder name wasnt specifically "Petromod" the code to spread the corporation with the refinery wouldnt work. So theres lines of code somewhere directly tied to the a folder address
 
Eh, I don't mean to be a nit-picker, but aren't tabs a no-no in Python? I thought it was only kosher to use blank spaces for indentation. :crazyeye:
I'm not sure about that, in civ they've used them(atleast in the files I have). And when using spaces when the other file uses tabs might cause weird errors sometimes. I can be wrong too.

Why that code worked with those line breaks remains a mystery to me also, but those lines perhaps use another type of line breaks? Otherwise I use backslash (\) for arbitrary line breaks in Python code myself.
Again, I'm not too familiar with python to say how it should be done. But myself I haven't broken them in many lines and try to keep one line in one line and another ine in another line, and it has been working. :)


Also I noticed with the vanilla petromod if the mod folder name wasnt specifically "Petromod" the code to spread the corporation with the refinery wouldnt work. So theres lines of code somewhere directly tied to the a folder address
Really? Could you give me a link so I can check it out?
 
Check if there are directions to the mod folder somewhere in the .ini files or such. Because if you tell the mod to look for the XML in another mod, your own mod won't work.
 
Top Bottom