Another Noob Python Question

Okay, I've got rid of that guy, but I now have a different error. It seems getType is not usable after pUnit
Here is my current code:
PHP:
def unitCannotMoveInto(self,argsList):
		ePlayer = argsList[0]
		iUnitId = argsList[1]
		iPlotX = argsList[2]
		iPlotY = argsList[3]
        
        
        ## Locomotive Route Restriction
		pUnit = gc.getPlayer(ePlayer).getUnit(iUnitId)
		iTrainType = gc.getInfoTypeForString ( "UNIT_TRAIN" )
		if pUnit.getType() == iTrainType:
			pPlot = CyMap().plot(iPlotX, iPlotY)
			iRoute = gc.getInfoTypeForString ( "ROUTE_RAILROAD" )
			CyInterface().addImmediateMessage("Testing plot with route %d against %d" % (pPlot.getRouteType(), iRoute), "")
			if pPlot.getRouteType() != iRoute:
				return True
        
        ## End Edit
		CyInterface().addImmediateMessage("Allowing move", "")
		return False
And the Error:
Spoiler :
File "CvGameInterface", line 66, in unitCannotMoveInto

File "CvGameUtils", line 67, in unitCannotMoveInto

AttributeError: 'CyUnit' object has no attribute 'getType'
ERR: Python function unitCannotMoveInto failed, module CvGameInterface
 
Awesome, it worked perfectly! :woohoo: Thanks General Tso! And a big thanks to The J and EmporerFool for helping me as well. :D

Here is the code, if anyone wants it. :)
PHP:
def unitCannotMoveInto(self,argsList):
		ePlayer = argsList[0]
		iUnitId = argsList[1]
		iPlotX = argsList[2]
		iPlotY = argsList[3]
        
        
        ## Locomotive Route Restriction
		pUnit = gc.getPlayer(ePlayer).getUnit(iUnitId)
		iTrainType = gc.getInfoTypeForString ( "UNIT_TRAIN" )
		if pUnit.getUnitType() == iTrainType:
			pPlot = CyMap().plot(iPlotX, iPlotY)
			iRoute = gc.getInfoTypeForString ( "ROUTE_RAILROAD" )
			if pPlot.getRouteType() != iRoute:
				return True
        
        ## End Edit
		return False
 
Glad you got it working. :goodjob:

It's a communication with c++, and it cares about case-sensitivy (python itself doesn't care).

Python cares as well. Most programming languages (all but one that I've used) are case sensitive.
 
Python cares as well. Most programming languages (all but one that I've used) are case sensitive.

Ah, good to know, so i will not run in more errors.

And i thought, python is a real flexible language :shake:.
 
And i thought, python is a real flexible language :shake:.

But that makes Python more flexible. You can have two variables called x and X for maximum confusion!

It's actually a simple runtime-cost decision. Having to convert a name to lowercase every time the interpreter looks it up in a dictionary would slow it down considerably given that nearly everything that happens in Python is a dictionary lookup.
 
But that makes Python more flexible. You can have two variables called x and X for maximum confusion!

And i thought, a class, a function and a variable called x would be enough confusing :D.

It's actually a simple runtime-cost decision. Having to convert a name to lowercase every time the interpreter looks it up in a dictionary would slow it down considerably given that nearly everything that happens in Python is a dictionary lookup.

Sounds logical .
 
Top Bottom