[Python] Help with first script

Temrek

Chieftain
Joined
Jun 19, 2008
Messages
28
As the title may indicate, I have never worked with python before and I am unable to get this script to work.
Code:
def onGameStart(self, argsList):
		'Called at the start of the game'
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			for iPlayer in range(gc.getMAX_PLAYERS()):
				player = gc.getPlayer(iPlayer)
				if (player.isAlive() and player.isHuman()):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
					popupInfo.setText(u"showDawnOfMan")
					popupInfo.addPopup(iPlayer)
					pStartPlot = player.getStartingPlot()
           				plotx = pPlot.getX()
                                        ploty = pPlot.getY()
					player.found(plotx, ploty)
                    			pCity = player.getCity(0)
                                        if player.hasTrait(gc.getInfoTypeForString('TRAIT_CITY_STATE')):
						pCity.setPopulation(3)
						pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_ORGANIZED_MANUFACTURE'), true)
						pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_ADVANCED_ANCESTORS'), true)

It modifies the file CvEventManager.py in the mods python directory, the dawn of man popup shows and the city is founded with the correct population, but no buildings are added there. So can you see whats wrong with it?
 
Do you have Python exceptions turned on? I took a very quick look at your code after pasting it in a Python editor and there where some indent errors. I'm not sure if the errors where caused by copying and pasting or if they are in your original code. With Python exceptions turned on you should get an error message if that is the problem.

To turn on Python exceptions click on the Civ4config shortcut in your game folder and edit this line:
HidePythonExceptions = 1
to
HidePythonExceptions = 0

When editing a mod it is usually a good idea to always have Python exceptions turned on.
 
Exceptions can help, but it's painful if you get multiple and you can't view them later. You can also make the exceptions get written to a log file for later checking (plus you can alt-tab, check the file, and alt-tab back into the game).

Turn on the logging system and then look for the file in the BTS My Games folder: "Logs/PythonErr.log".

While the indentation was indeed malformed (never mix tabs and spaces; set your editor to use tabs as that's what most of the Civ code uses), I don't think it's the problem here. The reason is that the bad indentation is before the player.found() call, and you say the city is founded.

I think the problem is your use of the old API function. Cities can now have more than 1 of each building, so you don't set that the city has a building, you set how many it has:

Code:
...
pCity.setPopulation(3)
pCity.[B]setNumRealBuilding[/B](gc.getInfoTypeForString('BUILDING_ORGANIZED_MANUFACTURE'), [B]1[/B])
pCity.[B]setNumRealBuilding[/B](gc.getInfoTypeForString('BUILDING_ADVANCED_ANCESTORS'), [B]1[/B])
 
Back
Top Bottom