User:DonQuich: Difference between revisions

From Civilization Modding Wiki
Jump to navigationJump to search
m (testing my bot)
m (testing my bot)
Line 3: Line 3:
Parameters flagged with this pseudo-type are actually '''integers'''. <br/>
Parameters flagged with this pseudo-type are actually '''integers'''. <br/>
Pseudo-types do not exist in LUA, they only serve a documentation purpose on the wiki.<br/>
Pseudo-types do not exist in LUA, they only serve a documentation purpose on the wiki.<br/>
Integers labeled as 'PlotTypeID' corresponds to the constants defined in the '''PlotTypes''' LUA enumeration.<br/>
Integers labeled as 'TerrainID' corresponds to the 'ID' column of the [[Civ5Terrains]] XML table.<br/>
The values in the 'ID' and 'Type' columns are also dynamically stored on startup in the '''TerrainTypes''' LUA enumeration.<br/>


==PlotTypes enumeration ==
==TerrainTypes enumeration ==
A LUA enumeration is a just a regular table. It is commonly used to store constants, the keys being the constants' names and the pairs the corresponding values.
A LUA enumeration is a just a regular table. <br/>
Below are the values found in this enumeration.
It is commonly used to store constants, the keys being the constants' names and the pairs the corresponding values.<br/>


On startup, the game reads the [[Civ5Terrains]] data table and stores key/value pairs in the LUA enumeration. <br/>
The keys are the strings from the 'Type' column and the values are the integers from the 'ID' column.<br/>
Below are the values found in an unmodded game updated with Gods & Kings 1.0.1.705 (August 2012).


{|
{|
Line 16: Line 21:
!align="left" |Value
!align="left" |Value
|-
|-
| "NO_PLOT"
| "NO_TERRAIN"
|
|
| -1
| -1
|-
|-
| "PLOT_MOUNTAIN"
| "TERRAIN_GRASS"
|
|
| 0
| 0
|-
|-
| "PLOT_HILLS"
| "TERRAIN_PLAINS"
|
|
| 1
| 1
|-
|-
| "PLOT_LAND"
| "TERRAIN_DESERT"
|
|
| 2
| 2
|-
|-
| "PLOT_OCEAN"
| "TERRAIN_TUNDRA"
|
|
| 3
| 3
|-
|-
| "NUM_PLOT_TYPES"
| "TERRAIN_SNOW"
|
|
| 4
| 4
|-
| "TERRAIN_COAST"
|
| 5
|-
| "TERRAIN_OCEAN"
|
| 6
|-
| "TERRAIN_MOUNTAIN"
|
| 7
|-
| "TERRAIN_HILL"
|
| 8
|-
| "NUM_TERRAIN_TYPES"
|
| 9
|}
|}


==Examples==
==Examples==


Here is how to use the LUA enumeration to retrieve the ID from the 'type'. The variable 'id' will be assigned the value 4.<pre>
Here are different ways to query the database to retrieve the ID from the 'type'. The variable 'id' will be assigned the value 0. See also [[Civ5Lua/GameInfo|GameInfo]].<pre>
local id = PlotTypes.NUM_PLOT_TYPES
local id = GameInfo.Civ5Terrains.TERRAIN_GRASS.ID
local id = PlotTypes["NUM_PLOT_TYPES"]
local id = GameInfo["Civ5Terrains"]["TERRAIN_GRASS"]["ID"]
local id = GameInfo.Civ5Terrains{Type="TERRAIN_GRASS"}().ID
</pre>
</pre>
Alternatively you could use this ID to retrieve the value of the 'Description' column. Those examples will return and assign ''"TXT_KEY_TERRAIN_GRASS"''.<pre>
local description = GameInfo.Civ5Terrains.TERRAIN_GRASS.Description
local description = GameInfo["Civ5Terrains"]["TERRAIN_GRASS"]["Description"]
local description = GameInfo.Civ5Terrains{ID="TERRAIN_GRASS"}().Description
</pre>
Here is how to use the LUA enumeration to retrieve the ID from the 'type'. The variable 'id' will be assigned the value 9.<pre>
local id = TerrainTypes.NUM_TERRAIN_TYPES
local id = TerrainTypes["NUM_TERRAIN_TYPES"]
</pre>
==Referencing methods==
*'''void'''[[Civ5Lua/Plot|Plot]]:[[Civ5Lua/Plot/SetTerrainType|SetTerrainType]]([[Civ5Lua/TerrainID|TerrainID]] type)


[[Category:Civ5Lua]]
[[Category:Civ5Lua]]

Revision as of 04:20, 9 August 2012

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

Parameters flagged with this pseudo-type are actually integers.
Pseudo-types do not exist in LUA, they only serve a documentation purpose on the wiki.
Integers labeled as 'TerrainID' corresponds to the 'ID' column of the Civ5Terrains XML table.
The values in the 'ID' and 'Type' columns are also dynamically stored on startup in the TerrainTypes LUA enumeration.

TerrainTypes enumeration

A LUA enumeration is a just a regular table.
It is commonly used to store constants, the keys being the constants' names and the pairs the corresponding values.

On startup, the game reads the Civ5Terrains data table and stores key/value pairs in the LUA enumeration.
The keys are the strings from the 'Type' column and the values are the integers from the 'ID' column.

Below are the values found in an unmodded game updated with Gods & Kings 1.0.1.705 (August 2012).

Key Value
"NO_TERRAIN" -1
"TERRAIN_GRASS" 0
"TERRAIN_PLAINS" 1
"TERRAIN_DESERT" 2
"TERRAIN_TUNDRA" 3
"TERRAIN_SNOW" 4
"TERRAIN_COAST" 5
"TERRAIN_OCEAN" 6
"TERRAIN_MOUNTAIN" 7
"TERRAIN_HILL" 8
"NUM_TERRAIN_TYPES" 9

Examples

Here are different ways to query the database to retrieve the ID from the 'type'. The variable 'id' will be assigned the value 0. See also GameInfo.

local id = GameInfo.Civ5Terrains.TERRAIN_GRASS.ID
local id = GameInfo["Civ5Terrains"]["TERRAIN_GRASS"]["ID"]
local id = GameInfo.Civ5Terrains{Type="TERRAIN_GRASS"}().ID

Alternatively you could use this ID to retrieve the value of the 'Description' column. Those examples will return and assign "TXT_KEY_TERRAIN_GRASS".

local description = GameInfo.Civ5Terrains.TERRAIN_GRASS.Description
local description = GameInfo["Civ5Terrains"]["TERRAIN_GRASS"]["Description"]
local description = GameInfo.Civ5Terrains{ID="TERRAIN_GRASS"}().Description

Here is how to use the LUA enumeration to retrieve the ID from the 'type'. The variable 'id' will be assigned the value 9.

local id = TerrainTypes.NUM_TERRAIN_TYPES
local id = TerrainTypes["NUM_TERRAIN_TYPES"]

Referencing methods