Page 1 of 1

How to obtain unitdef by unitdefid?

Posted: 31 Jul 2010, 22:38
by echoone
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.

Code: Select all

unitdef = Unit.getDef( unitid )
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.

Code: Select all

name = UnitDef.getName( unitdefid )
UnitDef.getUnitDefByName( name )
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.

Re: How to obtain unitdef by unitdefid?

Posted: 31 Jul 2010, 23:58
by AF
This doesn't make much senseless, since a unitdef is always the same, a united represents a unit type, not a unit, so either you mean the united is the same as the original which seems obvious, or you mean the builders united when you are referring to the original, at which point either the builder can build itself, or you've confused everyone and yourself

Further clarification necessary!! If possible in a single sentence

Re: How to obtain unitdef by unitdefid?

Posted: 01 Aug 2010, 01:12
by echoone
echoone wrote:How can I take that list of unitdefids and obtain each corresponding unitdef?

Re: How to obtain unitdef by unitdefid?

Posted: 01 Aug 2010, 02:54
by AF
Normally the API provides an array of unitdefs, which are indexed by ID, I cant speak for your API of choice, but that's how it worked in the legacy API. I dont know why you couldnt just use the name strings though =/

Re: How to obtain unitdef by unitdefid?

Posted: 01 Aug 2010, 08:31
by hoijui
as AF suggests, thi is a Python AI Interface issue, not general/C AI (Interface) one.