Help with python error?

Fastjack

Chieftain
Joined
Nov 9, 2008
Messages
56
Location
Louisville, KY
I am customizing the tectonics map script to suit my mod (with the creator's permission)... here is the code. This section is the only thing I have changed.

Code:
	def createMap(self):
		for y in range(self.mapHeight - 5):
			for x in range(self.mapWidth):
				i = y*self.mapWidth + x
				height = self.heightMap[i]
				if (height > self.peakAltitude):
					if (self.dice.get(7,"Random pass") == 6):
						self.plotTypes[i] = PlotTypes.PLOT_HILLS
					else:
						self.plotTypes[i] = PlotTypes.PLOT_PEAK
				elif (height > self.hillAltitude):
					if (self.dice.get(20,"Random peak") == 19):
						self.plotTypes[i] = PlotTypes.PLOT_PEAK
					else:
						self.plotTypes[i] = PlotTypes.PLOT_HILLS
				elif (height > self.landAltitude):
					self.plotTypes[i] = PlotTypes.PLOT_LAND
				else:
					self.plotTypes[i] = PlotTypes.PLOT_OCEAN
		for y in range((self.mapHeight - 5), (self.mapHeight + 5)):
			for x in range(self.mapWidth):
				i = y*self.mapWidth + x
					if y <= (self.mapHeight - 3):
						self.plotTypes[i] = PlotTypes.PLOT_ICE
					elif y <= (self.mapheight + 3):
						self.plotTypes[i] = PlotTypes.PLOT_PEAK
					else:
						self.plotTypes[i] = PlotTypes.PLOT_HILLS
		for y in range((self.mapHeight + 5), (self.mapHeight * 2)):
			for x in range(self.mapWidth):
				i = y*self.mapWidth + x
				height = self.heightMap[i]
				if (height > self.peakAltitude):
					if (self.dice.get(7,"Random pass") == 6):
						self.plotTypes[i] = PlotTypes.PLOT_HILLS
					else:
						self.plotTypes[i] = PlotTypes.PLOT_PEAK
				elif (height > self.hillAltitude):
					if (self.dice.get(20,"Random peak") == 19):
						self.plotTypes[i] = PlotTypes.PLOT_PEAK
					else:
						self.plotTypes[i] = PlotTypes.PLOT_HILLS
				elif (height > self.landAltitude):
					self.plotTypes[i] = PlotTypes.PLOT_LAND
				else:
					self.plotTypes[i] = PlotTypes.PLOT_OCEAN

This is the error message, it just pops up 6 or 7 times just after launcher. I don't see any syntax errors, do you? I don't really know Python, just monkey see monkey do-ing it.

Code:
Traceback (most recent call last):

File "<string>", line 1, in ?
File "<string>", line 35, in load_module
File "<string>", line 13, in_get_code
File "Tectonics", line 493
     if y <= (self.mapHeight - 3):

     ^

    SyntaxError: invalid syntax
 
You have bad indent.
Code:
				i = y*self.mapWidth + x
					if y <= (self.mapHeight - 3):
should be
Code:
				i = y*self.mapWidth + x
				if y <= (self.mapHeight - 3):
(same on following lines of course).
The if block is markes by indenting, so if you indent one too many, the interpreter gets lost.
 
Thanks for all your help, really. Now it is telling me Voronoimap has no self.mapHeight attribute... All I changed was adding that "/2"... I can't see how it isn't able to figure out what the self.mapHeight is.
Code:
class voronoiMap:
	def __init__(self,landPlates,seaPlates,hotspotsF):
		map = CyMap()
		gc = CyGlobalContext()
		self.dice = gc.getGame().getMapRand()
		self.mapWidth = map.getGridWidth()
		self.mapHeight = map.getGridHeight()/2
		self.plotTypes = [PlotTypes.PLOT_OCEAN] * (self.mapWidth*self.mapHeight)
		self.heightMap = [0] * (self.mapWidth*self.mapHeight)
		self.plateMap = [0] * (self.mapWidth*self.mapHeight)
		self.numContinents = landPlates
		self.hotSpotFrequency = hotspotsF
		self.numSeaPlates = seaPlates + 1 # plate 0 is for initialisation
		self.plate = [0] * (self.numContinents + self.numSeaPlates)
		# plateSize is a random number which gives the probability of growing a plate
		self.plateSize = [0] * (self.numContinents + self.numSeaPlates)
		self.altitudeVariation = 2
		self.peakAltitude = 12
		self.hillAltitude = 9
		self.landAltitude = 6
		for x in range(self.mapWidth):
			for y in range(self.mapHeight):
				i = y*self.mapWidth + x
				self.plotTypes[i] = PlotTypes.PLOT_OCEAN

It lets me through the error, but the map it makes has no separation and has two horizontal bars of desert in it.
 
You'd better send me your modded file so I can check it. I may have some time to look it up during the week-end. Just attach the whole file (you may need to zip it first) here.
 
OK first you need to tell
self.mapHeight = map.getGridHeight() / 2
at line 180.
Actually, it'd be better to sub class voronoiMap, but I'll keep the suggested changes to a minimum.
Line 498 seems badly indented, but I think you want peaks there, so you should replace lines 490-502 by something like this:
Code:
		for y in range((self.mapHeight - 6), (self.mapHeight + 5)):
			for x in range(self.mapWidth):
				i = y*self.mapWidth + x
				self.plotTypes[i] = PlotTypes.PLOT_PEAKS
		for y in range((self.mapHeight + 6), (self.mapHeight * 2 - 1)):
			for x in range(self.mapWidth):
				i = y*self.mapWidth + x
				surfaceI = ( y - self.mapHeight -12 )self.mapWidth + x
				height = self.heightMap[surfaceI]
I can't try right now, but this should hopefully give better results.
 
What is this "sub classing" of which you speak? Also, I am getting the same error with the changes. As for the middle loop, I decided to have 3 squares of either ice or limestone, followed by peaks. I will change what terrain is being done there once I am farther into the mod.
 
I am at work now, and I realised I didn't change the ranges involved in the for loops. Would that possibly cause the problem? We need to change it because the first horizontal row is counted as row 0, right?
 
There's a range problem (not enough plots initialised) and some case problems: maphieght is different from mapHeight.
As for classes, it's an Object Oriented Programming notion (the basis of it).
You should try to learn a bit more about python if you want to be able to change the file to do what you would like.
Here's a modified attached version that works. I removed all the stuff that's not needed. You'll notice I removed some options like Pangaea or Mediterranean because they wouldn't fit with the changes made.
 

Attachments

Thanks, I will try it when I get home. C++ was that language I learned 4 years ago while I was focused on learning animation... I am picking it up fairly quickly. I just need to learn in what way this particular language likes to be finicky. After that they are all almost the same.

As for the subclasses, if I can see an example I will be golden.
 
Examples of subclasses in tectonics: PangaeaVoronoiMap inherits voronoiMap but changes starting land plate locations.
Subclasses are the same concept in python as in C++ where a class inherits from another by ClassA : public ClassB and you can change virtual methods. In python, all methods can be changed and specialised.
 
Huh, with that file, I get it error free, but I don't have any kind of divide at all. It acts as if we didn't mod the file. Also, I have extra green areas of grasslands that have hard edges... is that normal?
 
No it is not normal.
There is a huge span of mountains running E-W when I generate a map.
Just to make sure, do you have BtS? Normally the only thing that should be wrong without is the Cytranslator part Firaxis added, which can be replaced by strings and shouldn't affect the script.
 
Yes, I have BtS. It is updated to the latest version... I know there is a temp directory in Civ4, where exactly is that? I read about it on these forums but I forgot where it is and I can't find the thread anymore. Although that doesen't make sense, because if it were still loading up my old version I would be getting errors... odd.
 
If you are using Vista you need to take full user ownership of the game directory or extremely confusing things can happen. Also, you might turn off file caching in your ini file, that also can make modding confusing as you aren't always using the latest file.
 
I am not using Vista, and the file caching is already off. In the game menu, the "civ version" is 317, but the save version is 3.13... is that the final patch?
 
Well I am going to start another thread in the Python help forum, as when my game starts functioning I will have what I need. Thanks a whole lot for all of your help, DiCesare.
 
Last Civ version is 3.17. I don't know why the save version would be different.
I'm sorry I can't help you more with this as it works for me.:sad:
 
Back
Top Bottom