Jeckel
Sep 30, 2006, 06:26 AM
Say you have a CyObject.
It could be a CyPlayer, CyUnit, CyPlot, ect, but you don't know.
I've been looking through the API thinking I would find a CyUnit.isUnit or a gc.isUnit(CyUnit) at the least, but so far I've haven't found anything.
Could anyone offer some advice or suggestiongs?
Lord Olleus
Sep 30, 2006, 06:38 AM
what exactly are you trying to do?
In python you can't (usualy) create new CyObject, you only create a variable which points to an already existing Object.
for example in;
pUnit = pPlayer.getUnit(0)
The right hand side returns a CyUnit, and the pUnit variable is then set to equal that object. Nothing here is actualy being created, there is no new unit.
Jeckel
Sep 30, 2006, 07:49 AM
Well basicly I have this method getDataIDStr(pObj).
I want to get a unique id string for whatever pObj is passed in.
If a pUnit is passed in I want the strID to be
str(pUnit.getOwner) + "_" + str(pUnit.getID()) + "_" + str(pUnit.getUnitType())
but if it is a pCity I want it to be
str(pCity.getOwner) + "_" + str(City.getID()) + "_" + str(City.getCivilizationType())
and if it is a pPlot it would be
str(pPlot.getX()) + "_" + str(pPlot.getY())
So I am trying to figure a way to tell if the pObj passed in is a pPlot, pCity, ect.
Any ideas? :)
Lord Olleus
Sep 30, 2006, 09:03 AM
Ah I see. No there is no way of doing this that I can think of (in python anyway). I think you're better off having 3 different functions.
Melinko
Sep 30, 2006, 11:18 AM
Nods, cool, just thought I would ask. :)
Gerikes
Sep 30, 2006, 04:23 PM
Well basicly I have this method getDataIDStr(pObj).
I want to get a unique id string for whatever pObj is passed in.
If a pUnit is passed in I want the strID to be
str(pUnit.getOwner) + "_" + str(pUnit.getID()) + "_" + str(pUnit.getUnitType())
but if it is a pCity I want it to be
str(pCity.getOwner) + "_" + str(City.getID()) + "_" + str(City.getCivilizationType())
and if it is a pPlot it would be
str(pPlot.getX()) + "_" + str(pPlot.getY())
So I am trying to figure a way to tell if the pObj passed in is a pPlot, pCity, ect.
Any ideas? :)
Check out the "type" function in python, used like this:
print type(pUnit)
returns:
<class 'CvPythonExtensions.CyUnit'>
By seeing what the type function returns, you can see what type of object it is.