User:DonQuich: Difference between revisions
m (testing my bot) |
m (testing my bot) |
||
Line 1: | Line 1: | ||
The 'TerrainID' pseudo-type is actually a regular '''integer'''.<br/> | |||
The 'TerrainID' pseudo-type is actually a regular '''integer'''. <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 'TerrainID | 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/> | The values in the 'ID' and 'Type' columns are also dynamically stored on startup in the '''TerrainTypes''' LUA enumeration.<br/> | ||
== TerrainTypes enumeration == | |||
A LUA enumeration is a just a regular table.<br/> | |||
==TerrainTypes enumeration == | |||
A LUA enumeration is a just a regular table. <br/> | |||
It is commonly used to store constants, the keys being the constants' names and the pairs the corresponding values.<br/> | 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/> | 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/> | 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). | Below are the values found in an unmodded game updated with Gods & Kings 1.0.1.705 (August 2012). | ||
{| | {| | ||
|- | |- | ||
!align="left" |Key | !align="left" |Key | ||
! | ! | ||
!align="left" |Value | !align="left" |Value | ||
|- | |- | ||
|"NO_TERRAIN | |"NO_TERRAIN | ||
| | | | ||
|align="right" |-1 | |align="right" |-1 | ||
|- | |- | ||
|"TERRAIN_GRASS | |"TERRAIN_GRASS | ||
| | | | ||
|align="right" |0 | |align="right" |0 | ||
|- | |- | ||
|"TERRAIN_PLAINS | |"TERRAIN_PLAINS | ||
| | | | ||
|align="right" |1 | |align="right" |1 | ||
|- | |- | ||
|"TERRAIN_DESERT | |"TERRAIN_DESERT | ||
| | | | ||
|align="right" |2 | |align="right" |2 | ||
|- | |- | ||
|"TERRAIN_TUNDRA | |"TERRAIN_TUNDRA | ||
| | | | ||
|align="right" |3 | |align="right" |3 | ||
|- | |- | ||
|"TERRAIN_SNOW | |"TERRAIN_SNOW | ||
| | | | ||
|align="right" |4 | |align="right" |4 | ||
|- | |- | ||
|"TERRAIN_COAST | |"TERRAIN_COAST | ||
| | | | ||
|align="right" |5 | |align="right" |5 | ||
|- | |- | ||
|"TERRAIN_OCEAN | |"TERRAIN_OCEAN | ||
| | | | ||
|align="right" |6 | |align="right" |6 | ||
|- | |- | ||
|"TERRAIN_MOUNTAIN | |"TERRAIN_MOUNTAIN | ||
| | | | ||
|align="right" |7 | |align="right" |7 | ||
|- | |- | ||
|"TERRAIN_HILL | |"TERRAIN_HILL | ||
| | | | ||
|align="right" |8 | |align="right" |8 | ||
|- | |- | ||
|"NUM_TERRAIN_TYPES | |"NUM_TERRAIN_TYPES | ||
| | | | ||
|align="right" |9 | |align="right" |9 | ||
Line 71: | Line 64: | ||
== Examples == | |||
==Examples== | Here is how to use the LUA enumeration to retrieve the ID from the 'type'. Those examples will return and assign the integer value 0. | ||
<pre> | |||
Here is how to use the LUA enumeration to retrieve the ID from the 'type'. Those examples will return and assign the integer value 0.<pre> | |||
local id = TerrainTypes.TERRAIN_GRASS | local id = TerrainTypes.TERRAIN_GRASS | ||
local id = TerrainTypes["TERRAIN_GRASS"] | local id = TerrainTypes["TERRAIN_GRASS"] | ||
</pre> | </pre> | ||
Here are different ways to query the database to retrieve the ID from the 'type'. Those examples will return and assign the integer value 0. See also [[Civ5Lua/GameInfo|GameInfo]].<pre> | Here are different ways to query the database to retrieve the ID from the 'type'. Those examples will return and assign the integer value 0. See also [[Civ5Lua/GameInfo|GameInfo]]. | ||
<pre> | |||
local id = GameInfo.Civ5Terrains.TERRAIN_GRASS.ID | local id = GameInfo.Civ5Terrains.TERRAIN_GRASS.ID | ||
local id = GameInfo["Civ5Terrains"]["TERRAIN_GRASS"] | local id = GameInfo["Civ5Terrains"].["TERRAIN_GRASS"].ID | ||
local id = GameInfo.Civ5Terrains{Type="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 the value | Alternatively you could use this ID to retrieve the value of the 'Description' column. Those examples will return and assign the value TXT_KEY_TERRAIN_GRASS. | ||
<pre> | |||
local description = GameInfo.Civ5Terrains[0].Description | local description = GameInfo.Civ5Terrains[0].Description | ||
local description = GameInfo["Civ5Terrains"][0]["Description"] | local description = GameInfo["Civ5Terrains"][0]["Description"] | ||
local description = GameInfo.Civ5Terrains{ID= | local description = GameInfo.Civ5Terrains{ID=[0}().Description | ||
</pre> | </pre> | ||
==Methods using those identifies== | |||
==Methods using those | * '''void''' [[Civ5Lua/Plot|Plot]]:[[Civ5Lua/Plot/SetTerrainType|SetTerrainType]]([[Civ5Lua/TerrainID|TerrainID]] type) | ||
*'''void''' [[Civ5Lua/Plot|Plot]]:[[Civ5Lua/Plot/SetTerrainType|SetTerrainType]]([[Civ5Lua/TerrainID|TerrainID]] type) | |||
[[Category:Civ5Lua]] | [[Category:Civ5Lua]] |
Revision as of 08:19, 9 August 2012
The 'TerrainID' pseudo-type is actually a regular integer.
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 is how to use the LUA enumeration to retrieve the ID from the 'type'. Those examples will return and assign the integer value 0.
local id = TerrainTypes.TERRAIN_GRASS local id = TerrainTypes["TERRAIN_GRASS"]
Here are different ways to query the database to retrieve the ID from the 'type'. Those examples will return and assign the integer 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 the value TXT_KEY_TERRAIN_GRASS.
local description = GameInfo.Civ5Terrains[0].Description local description = GameInfo["Civ5Terrains"][0]["Description"] local description = GameInfo.Civ5Terrains{ID=[0}().Description
Methods using those identifies
- void Plot:SetTerrainType(TerrainID type)