Civ5 API FAQ: Difference between revisions

From Civilization Modding Wiki
Jump to navigationJump to search
mNo edit summary
mNo edit summary
Line 18: Line 18:




=== Should you use the same notation ===
=== Should you use the same notation? ===
Well, it's up to you, there are arguments in favor of it and some others against it.
Well, it's up to you, there are arguments in favor of it and some others against it.
* Pro: it's widely used in the community and your code will harmonize with the one from Firaxis.
* Pro: it's widely used in the community and your code will harmonize with the one from Firaxis.

Revision as of 17:23, 21 September 2012

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


Firaxis Hungarian notation

Firaxis used a naming convention categorized as Hungarian Notation. The prefixes provide informations regarding the type.

  • s, sz and str mean a string.
Example: sName expects something like "Genghis Khan".
  • b means boolean.
Example: bHide expects true or false.
  • f means floating-point, a number.
Example: fScale expects a scale factor, may be 0.5, 1.0, 2.0, etc.
  • i means integer, a number. Sometimes it may be one of the identifiers listed on the main page.
Example: iPlayer expects a PlayerID while iWidth expects a width in pixels (50, 200, etc).
  • e means an identifier (integer) taken from a Lua enumeration.
Example: eBuilding expects a BuildingType. You could assign it with 10 or GameInfoTypes.BUILDING_SEAPORT , both are equivalent.
  • p means an API object (p means pointer but pointer is a C term with no relevance in Lua).
Example: pPlayer expects a Player object.


Should you use the same notation?

Well, it's up to you, there are arguments in favor of it and some others against it.

  • Pro: it's widely used in the community and your code will harmonize with the one from Firaxis.
  • Pro: you always now the type of a variable by looking at its name, which is useful since ModBuddy does not inform us about the type.
  • Con: it's not really necessary, most of the time a consistent naming is enough to know the type of a variable: for example playerID for a PlayerID and player for a Player.