Problem with custom events

Ace of Spades

GEM Fanboy
Joined
Feb 18, 2003
Messages
210
Location
Munich, Germany
Hello there,

first of all, thanks for the great mod! It really helps to make information much more accessible.

I encountered a small problem when combining the mod with a custom event manager though. I have attached the file to this post - maybe someone who knows more about python than I do can tell me why this error occurs.

There is just a tiny modification in the event manager, during the event onNukeExplosion (look for "def onNukeExplosion"), which is modded to destroy small cities entirely. Strangely enough, this event manager file works all well with an unmodded BTS, and I have been using it before - but once I add it to BUG, my in-game interface disappears.

I'd be glad if anyone can help me on this :)

Best Regards,
Ace
 
I'd be glad to take a look, but I think you forgot to attach the file.

What I can say without seeing the file is that if it's called CvEventManager.py or CvCustomEventManager.py, BUG includes its own versions of these files, so you must have overwritten BUG's. It would be really easy for me to alter yours to work with BUG though, so attach it and I'll see what I can do.
 
Sorry... I must have accidently skipped some step during uploading.

Thank you for your concern Mr.Emperor :)

Best Regards,
Ace
 

Attachments

  • CvEventManager.zip
    8.8 KB · Views: 59
The problem is unrelated to BUG; the indentation is incorrect. Try replacing the function with this one:

PHP:
	def onNukeExplosion(self, argsList):
		'Nuke Explosion'
		pPlot, pNukeUnit = argsList
		
		#	ace init nuke #
		if pPlot.isCity():
			if pPlot.getPlotCity().getPopulation() <= 10:
				CyInterface().addMessage(pPlot.getPlotCity().getOwner(), False, 25, "%s has been destroyed by %s's Nuke!" %(pPlot.getPlotCity().getName(), gc.getPlayer(pNukeUnit.getOwner()).getName()), '', 2, "", 7, pPlot.getX(), pPlot.getY(), False, False)    ## A message to the city's owner
				pPlot.getPlotCity().kill()        ## Kill the city
		# ace end nuke #
		
		CvUtil.pyPrint('Nuke detonated at %d, %d'
			%(pPlot.getX(), pPlot.getY()))
In Python, as opposed to most other programming languages, indentation whitespace is significant. It is always iffy to mix spaces and tabs in the same file.

I've attached the fixed (though untested) file for your convenience.
 
Many thanks for solving this, EmperorFool! I will try it as soon as I get home.

The strange thing is, it did not cause any errors or weird behaviour when I used it without BUG - I never tested if it actually did something (like the intended behavoiur), maybe for some obscure reason it just stayed harmless. That's why I supposed there had to be some interference with BUG - sorry for mixing this up!

Best Regards,
Ace
 
Typically, if you modify a Python that BUG does not modify, things should go smoothly. The real headaches arise when two mods modify the same Python file. In that case, care must be taken when merging the changes. If the changes are in different locations in the file, it's a lot easier. :)

When you get the dreaded "no interface" issue, unless you have modified the CvMainInterface.py file, 9 times out of 10 it is illegal syntax (e.g. indentation, typo, bad import, etc) in a Python file. The file "logs/PythonErr.log" in your "My Games/BtS" folder will show any Python exceptions being raised. You might need to enable logging in the CivIV.ini first. It's easier to use this file than try to read them from a popup.
 
Top Bottom