Lua Game Objects/GameInfo

From Civilization V Wiki

Jump to: navigation, search

GameInfo can be used to query different information from database. There are several ways to use it.

For additional information about the game database, see Gameplay Database Overview.

Contents

Listing all values

To list values of a particular table (like resources), use GameInfo.TableName() as method.

for resource in GameInfo.Resources() do
    print(resource.ID, resource.Type, resource.AIStopTradingEra)
end

Conditions can also be passed in to filter out rows of the table.

-- Raw SQL conditions
for row in GameInfo.Units("Combat > 10") do
     print(row.Type);
end
-- Table of key/value pairs which represent column/value conditions that are AND'd together
for row in GameInfo.Units{PrereqTech = "TECH_FLIGHT", Cost = 150} do
     print(row.Type);
end

Retrieving some values

To get particular values in some table, use

local id = GameInfo.Units.UNIT_WORKER.ID
local cost = GameInfo.Units.UNIT_WORKBOAT.Cost

It works, because in lua, it is equivalent to:

local id = GameInfo["Units"]["UNIT_WORKER"]["ID"]
local cost = GameInfo["Units"]["UNIT_WORKBOAT"]["Cost"]

Basically, GameInfo is a table of all existing tables, each table's items are accessible over item Type, and item values can be retrieved as table. All tables contain a string index if they contain a column "Type" and an integer index on the column "ID". For tables which contain one or the other or neither, they must be iterated via a for loop.

Reference of common tables

  • Resources -- Different types of resources available
  • Civilizations
  • Units
  • Buildings
  • Features
  • Improvements
  • Leaders
  • Resources
  • Terrains
  • Worlds -- Map sizes

Other tables match XML files or tables in the database. See XML Reference.

See also

Personal tools