# Civ/Civilization IV/Modding/Tutorials/Python Tutorial/Event scripting & Interface mods
## 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

## Events

Events are things which occur due to certain triggers. There is only certain amount of fixed triggers, and this ties down modders slightly, however the triggers will accommodate most scripts. If you open up CvEventManager.py, the event triggers run from line 193 down to line 747 (patch 1.52). There are nearly 60 different triggers that can be used, ranging from onUpdate which runs every frame (probably about 30 times a second), to onGameStart which runs only once, at the start of the game.
Most triggers have arguments associated with them. These arguments are stored in the argsList. Under most event headers these arguments are defined. It's usually pretty obvious what they do.
Perhaps the simplest method of adding events on triggers is to just to add the event into the events manager. This will work for small mods, although it raises certain compatibility issues. A better way of doing it is to create your own CvCustomEventManager file. I recommend Dr Elmer Jiggle's event manager (found here). It's a bit tricky to understand at first, but well worth it if you can get it working. For examples of it in action I'd check out any of TheLopez's ModComps (look in this forum).

### Things to note:

* The onEndPlayerTurn tigger does not occur at the end of a player's turn, instead it occurs at the end of the start of a player's turn, after all the cities have built, etc. If you want to do an event on the end of a player's turn you'll probably have to bodge up some code to do it at the start of the next player's turn. It would appear something similar goes on with onBeginGameTurn, and onEndGameTurn, although both occur at the END of the game turn rather than at the beginning like the player ones. Thanks to Kael for spotting this.

### Example

If, for instance, you wanted a message to come up on every player's screen at the start of every game turn (in other words, at the start of the first player's turn), you could replace this code in the event manager:
with the following code:
NOTE: When making a formal mod you shouldn't simply add stuff to the event manager like this as it can cause compatibility issues. Check out the custom event manager linked to above.

## Interface

As I mentioned in the introduction almost all of the GUI is created dynamically either when you enter the relevant screen, or at the start of the game. Just about all of it is moddable. The files for modding the interface are in .../Assets/Python/Screens.

### Things to note

* When placing items in the interface that the x and y co-ords that you enter will correspond to the top left hand corner of the item.
* Remember that the resolution can change. It may often be a good idea to change how your interface displays depending on the resolution. To find the X and Y resolutions you can use the code:
* If an item needs a name, that name must be unique to that item, or strange things start to happen.
* The way the techchooser script is written can make it quite hard to mod. Instead of being generated everytime you load up the screen, the techchooser is instead generated at the start of the game, and then only the colour changes are done in-game. To stop this happening in game, and to ensure that the techchooser shows the mods you make to it while you're game is running I suggest you comment out line 72 (screen.setPersistent(True)). This will make the techchooser be constantly regenerated while open, and although this may cause your computer to slow slightly, it should work better. Sometimes though, due to the way it is generated for techchooser mods you will have to restart the game to see any changes.
<--Previous Page