Civ/Civilization IV/Modding/Tutorials/Python Tutorial/The Basics

Contents

 * Page 1: Introduction
 * Page 2: The basics
 * Page 3: Using the API
 * Page 4: Event scripting & Interface mods
 * Page 5: Debugging
 * Page 6: Misc

The basics
As you should know by now, there are several different types of "thing" you can get in python: ints, floats, strings, and bools. You also might be aware of "pointers". I wasn't when I first came to python, so I'll give you a little heads-up about them.

Basically a pointer is a game entity. It can take the form of a unit, a plot (square), or a player. In the default python code, and in many modder's code, a variable is shown to be a pointer by prefacing it with "p". So pUnit will define a single unit in the game, pPlayer a single player.

Likewise, if a variable is prefaced with an "i" it is likely to be an integer (int) variable, and "b" a Boolean (bool) variable. iPlayer, for example, will probably be a player's individual ID number, rather then the pointer for the player.

It does sometimes get confusing, as most pointers have integers which are closely related to them. This method of naming things helps to avoid confusion in a language like python where variables need not be declared, however it is only a guideline, and just because a variable is named as if it were a certain type of variable, it won't necessarily be one.

I also would like to put a note here about "Types". In most xml entries you will need to enter something into a type field. This field is a very important link to python, though must be converted to an int for it to work properly. There is one function that you'll be finding yourself using over and over again, so I thought I'd put it here. This function will find the int corresponding to the type – and as most functions in the API (soon to come) will want the int value of the type it's very useful. For example: gc.getInfoTypeForString("TECH_MYSTICISM") will return the int corresponding to the tech Mysticism, which, as it is the first entry in the relevant xml file will be zero by default. gc.getInfoTypeForString("RELIGION_TAOISM") will return the int 6 by default, as it is the 7th religion listed.

If you don't get that last bit right now, don't worry – hopefully it'll come clear when you read the next section.

<--Previous Page Next page -->