Trying to base commerce bonus off of culture

HotFusion

Chieftain
Joined
Dec 15, 2009
Messages
69
Hey, I'm a non-programmer trying to play around with Python. I'm using PlatyPing's Gigapack mod and am using the code in there as a basis for experimenting with new ideas.

Anyways, I wanted to make a wonder that generates research based off of the city's culture. Here is the part that is causing me trouble:

Code:
if self.Wonder[0] != -1:
		WonderCity = CyMap().plot(self.Wonder[0], self.Wonder[1]).getPlotCity()
  		iBonus = WonderCity.getCulture(gc.getPlayer(0))      
		WonderCity.setBuildingCommerceChange (gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus

I know that hardcoding the player with getPlayer(0) is bad, but I'm taking baby steps here :) Obviously, getting a research bonus equal to your culture is crazy over powered, but right now I'm just trying to get the idea to work.

self.Wonder is a variable declared higher up in the code. The problem I'm having is with the last line. If I don't comment it out, it breaks my game (the game loads, but the user interface vanishes and you can't play the game). I'm surprised that the last line is the one causing the problem, because it's a straight copy/paste of PlatyPing's WillisTower code, which works. I'm guessing it has to do with getCulture not playing nice with setBuildingCommerceChange, but I have no idea how to proceed from here.
 
You seem to be missing one ) in the end of that last line. It might also be safer to remove the space after setBuildingCommerceChange. With the changes it should look like this:
Code:
		WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)
That should atleast prevent it from breaking your game.
 
Besides that, getCulture(x) has to take in an integer, definitely not gc.getPlayer(x)

Replace it with WonderCity.getOwner()
 
Thanks for the replies.

It turns out that the missing parenthesis was a copy/paste error when posting, not an actual coding error. I wish it had been the real mistake, because at least I can understand that kind of problem.

Platyping, I tried your suggestion and it helped, but did not fully solve the problem. The code now looks like this:

Code:
		if self.Wonder[0] != -1:
			WonderCity = CyMap().plot(self.Wonder[0], self.Wonder[1]).getPlotCity()
  		iBonus = WonderCity.getCulture(WonderCity.getOwner())      
			WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)

It still breaks the game unless I comment out the last line. That line is the only one I thought I understood and I have no idea why it is the one causing the problem or why it is failing in such a dramatic fashion.
 
Yeah, I even tried replacing it with a stock wonder just in case I borked the xml, but it still fails even then :confused:

EDIT: I should clarify a bit. The buidlingclass is definitely okay. When I comment out the offending line, I can see the new wonder in my civilipedia and even build it (although it doesn't do anything right now). The code I'm using is a near-copy of the Willis Tower, which is present in the same mod. My first test was to duplicate the Willis Tower effect (+1 gold for every corporation branch in the game), and that worked fine. For some reason, switching to culture is causing problems.
 
Thanks for the replies.

It turns out that the missing parenthesis was a copy/paste error when posting, not an actual coding error. I wish it had been the real mistake, because at least I can understand that kind of problem.

Platyping, I tried your suggestion and it helped, but did not fully solve the problem. The code now looks like this:

Code:
		if self.Wonder[0] != -1:
			WonderCity = CyMap().plot(self.Wonder[0], self.Wonder[1]).getPlotCity()
  		iBonus = WonderCity.getCulture(WonderCity.getOwner())      
			WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)

It still breaks the game unless I comment out the last line. That line is the only one I thought I understood and I have no idea why it is the one causing the problem or why it is failing in such a dramatic fashion.

If that is how the code really looks, then indentation is clearly out.
The last 3 lines should be in the same indentation level, (same number of tabs)
Whereas the first line should be just 1 tab to the left
 
EDIT: Ninja'ed by Platy

Good idea! Here's the log

Code:
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "<string>", line 52, in load_module
  File "CvEventInterface", line 17, in ?
  File "<string>", line 52, in load_module
  File "BugEventManager", line 102, in ?
  File "<string>", line 35, in load_module
  File "<string>", line 13, in _get_code
  File "
CvEventManager
", line 
513

    
WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)
    
^
SyntaxError
: 
invalid syntax

Failed to load python module CvEventInterface.
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
Traceback (most recent call last):

  File "CvAppInterface", line 81, in onLoad

AttributeError: 'module' object has no attribute 'onEvent'
ERR: Python function onLoad failed, module CvAppInterface
Traceback (most recent call last):

  File "CvAppInterface", line 88, in preGameStart

AttributeError: 'module' object has no attribute 'getEventManager'
ERR: Python function preGameStart failed, module CvAppInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface

It looks like a syntax error, but I can't find the problem. For reference, here is the problem line right next to the line that I based it off of, which works just fine:

Code:
WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)
WillisTowerCity.setBuildingCommerceChange (gc.getInfoTypeForString("BUILDINGCLASS_WILLIS_TOWER"), 0, iTotal)

The only difference I can see is the space between "Change" and "(gc.getInfo" but I've tried this with and without that space and it doesn't change things.
 
Told u, indentation error

Code:
		if self.Wonder[0] != -1:
			WonderCity = CyMap().plot(self.Wonder[0], self.Wonder[1]).getPlotCity()
  			iBonus = WonderCity.getCulture(WonderCity.getOwner())      
			WonderCity.setBuildingCommerceChange(gc.getInfoTypeForString("BUILDINGCLASS_WONDER"), 1, iBonus)

Number of tabs matters
 
Found it!

Platyping, my code had all of the lines evenly spaced like it should. I'm not sure how it got borked when pasting it to the forum.

Anyways, it turns out that Notepad2 doesn't support the tab key. It instead inserts two spaces whenever you press tab :crazyeye:. So everything looked fine but was totally wrong. I had to copy/paste real tabs from elsewhere in the code and use those instead. That fixed the problem.

Craziest issue ever. Thanks everyone! I never would have figured it out without the guidance here.
 
Back
Top Bottom