How to obtain unitdef by unitdefid?
Posted: 31 Jul 2010, 22:38
I'm not sure if this is an oversight in the AI interface, a bug in the skirmish interface, a bug in the python interface, or I flat out misunderstand how I'm to do this. First, allow me to explain what I'd doing and trying to do.
I have a unitid provided by the unit created callback. I then grab the unitdef from the Unit interface.
That all works as I expected. I then check the UnitDef.getBuildOptions() result. I'm told this returns the list of unitdefid(s) which the original unit of the obtained original unitdef is capable of building. Sure enough, I call UnitDef.getName() on each of the values obtained from my call to getBuildOptions() and they look like what you would expect the unit to be able to build. So far, so good.
So here's the question. How can I take that list of unitdefids and obtain each corresponding unitdef? I tried doing so in a round-about manner as follows, as I've not found a more direct route to obtain the information.
But that doesn't do what the name says. It only returns the original unitdefid, which is contrary to the method's name. Shouldn't it really be called, "getUnitDefIdByName"? Or perhaps the python interface is doing the wrong thing? Meaning, perhaps the interface should be returning the unitdef, as the name implies, and its mistakenly returning the unitdefid, which the name does not imply?
Shouldn't there be a UnitDef.getDef( unitdefid ) method or equivalent? Seems like there should be a very straight forward method for obtaining a unitdef by its given unitdefid. Seems like an obvious bit of functionality, which makes me think I'm overlooking something.
I think I'm stuck unless someone can straighten me out. Which wouldn't be the first time I needed straightening out.
--
I edit the message. I provided some clarifications which may have been confusing if careful attention was not given. Please re-read.
I have a unitid provided by the unit created callback. I then grab the unitdef from the Unit interface.
Code: Select all
unitdef = Unit.getDef( unitid )
So here's the question. How can I take that list of unitdefids and obtain each corresponding unitdef? I tried doing so in a round-about manner as follows, as I've not found a more direct route to obtain the information.
Code: Select all
name = UnitDef.getName( unitdefid )
UnitDef.getUnitDefByName( name )
Shouldn't there be a UnitDef.getDef( unitdefid ) method or equivalent? Seems like there should be a very straight forward method for obtaining a unitdef by its given unitdefid. Seems like an obvious bit of functionality, which makes me think I'm overlooking something.
I think I'm stuck unless someone can straighten me out. Which wouldn't be the first time I needed straightening out.

--
I edit the message. I provided some clarifications which may have been confusing if careful attention was not given. Please re-read.