Accessing category unitdef

Accessing category unitdef

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Accessing category unitdef

Post by code_man »

Hello

I need to know how to access the "category" field of unitdefs from lua.
The wiki specifies nothing and having tried just "category" brings up an error.

Specifically what i need is to check whetever a certain unit belongs to a category, i dont really know how to do that either once i have the category field as a string.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Accessing category unitdef

Post by Silentwings »

The wiki tells you on this page http://springrts.com/wiki/Lua_UnitDefs, where the format of the modCategories table is specified. For example:

Code: Select all

UnitDefs[unitDefID].modCategories['ship']
returns true if and only if the unitDefID has category ship.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Accessing category unitdef

Post by code_man »

Works like a charm, thanks.
Post Reply

Return to “Lua Scripts”