Help: Boolean value not working!

ww2commander

Emperor
Joined
Aug 23, 2003
Messages
1,243
Location
Australia
I have just got into learning python and have made some progress, but I seem to have run into a problem which I know is simple to solve but cant figure it out. :(

Below is some code that changes the season terrain of my map. The season code work fine but I cant seem to get the game to recognize the boolean value bReDraw (which I have bolded)!

The way the code works is as follows:
1. A popup passes a value to SelectRedrawMethod.
2. SelectRedrawMethod then passes the respective true/false flag to ChangeSeasons which should use it in the setTerrainType function when using the part.

The game does not recognise the value and ignores it. I checked the python logs and it says nothing! Can anyone suggest why setTerrainType does not recognise my boolean value. It works fine when I actually type in the value rather than use the boolean flag.

Code:
	def SelectRedrawMethod(argList):
		iButtonId = argsList[0]
		iData1 = argsList[1]
		iData2 = argsList[2]
		iData3 = argsList[3]
		iData4 = argsList[4]
		szText = argsList[5]
		bOption1 = argsList[6]
		bOption2 = argsList[7]

		pPlayer = gc.getPlayer(iData)
		iMethod = -1
		if iButtonId == 0:
			self.ChangeSeason(0)
		if iButtonId == 1:
			self.ChangeSeason(1)

	def ChangeSeason(self, value):
		[B]bReDraw = False[/B]
		if value == 0:
		    [B]bRedraw = True[/B]
		elif value == 1:
		    [B]bReDraw = False[/B]
		bFreeze = False
		if iTurn % 2 == 0:
		    szMessage = "Winter Freeze"
		    bFreeze = True
		else:
		    szMessage = "Spring Thaw"
		    bFreeze = False
		map = CyMap()
		for y in range(map.getGridHeight()):
			for x in range(map.getGridWidth()):
				plot = CyMap().plot(x,y)
				#iTerrainType = plot.getTerrainType()
				if bFreeze: #Make terrain into winter
					if plot.getTerrainType() == 0:
						plot.setTerrainType(12, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 1:
						plot.setTerrainType(13, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 3:
						plot.setTerrainType(14, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 5:
						plot.setTerrainType(15, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 6:
						plot.setTerrainType(16, True, [B]bRedraw[/B])
					if plot.getFeatureType() == 5 and plot.getFeatureVariety() == 0: #Leafy forest
						plot.setFeatureType(5, 4)
					elif plot.getFeatureType() == 5 and plot.getFeatureVariety() == 1: #Evergreen forest
						plot.setFeatureType(5, 3)                   
				else: # Make terrain into summer
					if plot.getTerrainType() == 12:
						plot.setTerrainType(0, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 13:
						plot.setTerrainType(1, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 14:
						plot.setTerrainType(3, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 15:
						plot.setTerrainType(5, True, [B]bRedraw[/B])
					elif plot.getTerrainType() == 16:
						plot.setTerrainType(6, True, [B]bRedraw[/B])
					if plot.getFeatureType() == 5 and plot.getFeatureVariety() == 4: #Snowy Leafy forest
						plot.setFeatureType(5, 0)
					elif plot.getFeatureType() == 5 and plot.getFeatureVariety() == 3: #Snowy Evergreen forest
						plot.setFeatureType(5, 1)
		return 1
 
Firstly, you've used bRedraw illogically and confusingly in the code. In binary, true == 1 and yet you're using 1 to mean false. Will be easy to confuse the code.

Secondly, if value is only possible as two different values (0 or 1) then use it as your boolean. You will have to enact my first point to do this or you'll be back to front.

Therefore:
Get rid of the two value if comparisons, and have plot.setTerrainPlot(*, True, value)
 
Thanks for the reply Dale. I changed things around as suggested but still no luck.

I decided to stick in some message outputs to see what is being passed....but it turns out its not getting as far as the SelectRedrawMethod function :(

It seems to be the actual popup causing the problem. I used your tutorial in creating this code so I am not sure what else to do!

I had a quick look at your RTW code and the way you handle popup inputs is different to the tutorial. This whole python thing is getting alittle too confusing for me. Why are popups so hard :cry:

EDIT: Here is the actual popup code I am using

Code:
	def CheckTurn(self, iTurn):

		'Called at the beginning of each turn'

		iPlayerNum = 0
		for iPlayer in range(gc.getMAX_PLAYERS()):
		    player = gc.getPlayer(iPlayer)
		    if player.isAlive():
			    iPlayerNum = iPlayerNum + 1
			    if player.isHuman():
				    popupInfo = CyPopupInfo()
				    popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
				    popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_SELECT_SEASON",()))
				    popupInfo.setData1(iPlayer)
				    popupInfo.setOnClickedPythonCallback("SelectRedrawMethod")
				    popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_BUTTON_REDRAW", ()), "")
				    popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_BUTTON_NOREDRAW", ()), "")
				    popupInfo.addPopup(iPlayer)
 
Yes.......
 
Nah, I don't hate Python anymore, now that I've mastered the basics of it. :D

Python is your friend...
 
Python may be ya friend, but know C++ and the SDK, and it becomes ya . .. .. .. .. .! :D
 
Thanks for all the help guys.

It turns out that there was several problems - the case was wrong, 'arglist' should have been 'argslist' and finally I should have paid more attention to Dale's popup tutorial when he specifically stated that the callback for the popups needs to be in CvScreenInterface.py :blush:

Slowly I am getting a hang of this python thingamajiggy! :crazyeye:
 
Back
Top Bottom