Getting string for integer type (unit:GetUnitClassType)

ww2commander

Emperor
Joined
Aug 23, 2003
Messages
1,243
Location
Australia
Just when I thought I was getting the hang of LUA, I get stumped by the most basic of things!

Is there a integer to string type function that converts 1 to the string UNITCLASS_WORKER?

When I use the function unit:GetUnitClassType() it returns the unitclass as an integer, yet I want to use the string equivalent for something and can't for the life of me figure out how to do it.
 
Nevermind.....have a strong head cold right now so brain is not functioning.

Just incase anyone wants to know the answer:

Use the GameInfo function with ".type" at the end

i.e:
unitClass = unit:GetUnitClassType()
stringType = GameInfo.UnitClasses[unitClass].Type
 
GameInfo lets you index tables by either ID (integer) or Type (string). So you can get the "row" either way, and then append .ID, .Type, .Description, etc to get whatever you want from the row.

The only other trick you might need with GameInfo is iterating over all rows in a table:

for row in GameInfo.UnitClasses() do
print(row.ID, row.Type, row.Description)
end
 
Don't forget

Code:
iUnitId = GameInfoTypes.UNIT_WARRIOR

to get the id of the warrior unit and also

Code:
for building in GameInfo.Buildings{SpecialistType = pSpecialistInfo.Type} do

to perform a query before iterating over the entries in the Buildings table
 
Back
Top Bottom