GameInfoTypes (Civ5 Type)

From Civilization Modding Wiki
Revision as of 15:19, 19 September 2012 by DonQuich (talk | contribs) (Bot update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Purpose

This object allows you to easily get a data row ID from its type. Example:

local settlerID = GameInfoTypes["UNIT_SETTLER"]
local settlerID = GameInfoTypes.UNIT_SETTLER

This object does reflect the changes made by mods. It includes the type for your custom units, buildings, etc.


Identifiers in the civ5 API

Anytime you need to provide a reference to a data row somewhere in the API, you will need to provide its ID value. You could directly use numeric constants but this is hard to read and understand, and it is not robust since those identifiers can be modified by mods or future expansions. This is why it is better to use GameInfoTypes to make the conversion. Example:

-- GetUnitType returns the data row's ID, we compare it to the settler row's ID.
if (pUnit:GetUnitType() == GameInfoTypes.UNIT_SETTLER) then
-- This is equivalent to the following line, but this latter one is less clean and robust.
if (pUnit:GetUnitType() == 0) then



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.