Python:

tsentom1

Bubble Dragon
Joined
Jul 24, 2007
Messages
1,000
Location
New York
Hey, I'm trying to get a building unable to be constructed if a certain game option is turned on. I know it's in CvGameUtils and I've done similar coding for preventing a building if another building was present or if the city isn't in range of a certain terrain feature, but I can't seem to get it to work with a game option.

in def cannotConstruct(self,argsList):

Code:
		if ( eBuilding == gc.getInfoTypeForString("BUILDING_A ") ):
			if ( CyGame().isOption(gc.getInfoTypeForString("GAMEOPTION_PICK_RELIGION"))==false ):
				return False				

			return True

doesn't work, neither does:

Code:
              if ( eBuilding == gc.getInfoTypeForString("BUILDING_A ") ):
			if ( CyGame().isOption(gc.getInfoTypeForString("GAMEOPTION_PICK_RELIGION"))==true ):
				return True

Am i just making a really obvious mistake I'm not noticing? Is it possible to tie this to a game option or if there's another way to do this (i.e. if Choose Religions is turned on you can't construct Building A)?
 
Easy stuff first ... Have you enabled the callback in PythonCallbackDefines.xml? Can you add a print statement just above your code to make sure it is being entered? If you print the value returned by getInfotypeForString, is it valid (not -1)?
 
Why is there a space after BUILDING_A in the first line of both examples? That's the thing that jumps out at me.

Also, while it probably isn't causing your problem, you can shorten your second if check to either
Code:
if CyGame().isOption(gc.getInfoTypeForString("GAMEOPTION_PICK_RELIGION")):
or
Code:
if not CyGame().isOption(gc.getInfoTypeForString("GAMEOPTION_PICK_RELIGION")):
depending on your needs. isOption() will return a boolean so you can just use it directly.
 
You should not be using getInfoTypeForString on GameOption constants. Instead, use this:

Code:
if ( eBuilding == gc.getInfoTypeForString("BUILDING_A ") ):
    return CyGame().isOption([B]GameOptionTypes.GAMEOPTION_PICK_RELIGION[/B])

The string you are passing in is probably not found, so gITFS returns -1 which is an invalid option.
 
Top Bottom