This tutorial details how the Rebels Python mod was done. It was requested by a non-programmer looking to get into Python modding and the specifics are detailed in this post.
Note however that this tutorial will only describe how this particular mod was done. You won't learn how to make your own Python mods, because this requires programming skill. If you wanna keep up with what happens in this tutorial you might wanna have this textbook handy. It will teach you all the Python you need to mod CivIV - and then some.
What this tutorial however does go into some detail about is how to do CivIV specific Python. Because there is a distinction between the language itself and its implementation for modding. And the latter you won't learn in the textbook.
I'll post one lesson at a time, each time adding some code and explaining what it does. Once all questions are answered I'll post another one, until the entire script is completed.
The first homework assignment is to open up the built-in Python console in CivIV. First you enable cheat mode in the Civilization4.ini file. Then you figure out what shortkey opens up the console. On a US keyboard it is supposedly shift + ~ but that doesn't seem to be true for other keyboard layouts. (On my Swedish keyboard its shift + ö.)
You know that you have found it if it says "Python 2.4.1" - if it doesn't then that's not it. (There are other consoles and tools also.) I believe that the shortkey to open the Python console always include the shift key though, so non-US modders could just try all keys together with the shift key...
Wikipedia might be able to offer clues as to what key it could be.
To test the Python console you write the following line on the command prompt:
If the console returns the words hello and world, then you have just joined the community of programmers, as you just executed your first program.
Also, you can do math with the console - and the result will be shown as long as you include the print command. Like:
(The print command isn't really used in modding though, but it can be used outside the console to print messages into the Python debug log.)
We'll use the Python console in the first lesson and again at the end of the course. You can of course follow the tutorial even without using the console, but then you won't be able to join in on the fun.![Big Grin :D :D](/data/assets/smilies/biggrin.gif)
Note however that this tutorial will only describe how this particular mod was done. You won't learn how to make your own Python mods, because this requires programming skill. If you wanna keep up with what happens in this tutorial you might wanna have this textbook handy. It will teach you all the Python you need to mod CivIV - and then some.
What this tutorial however does go into some detail about is how to do CivIV specific Python. Because there is a distinction between the language itself and its implementation for modding. And the latter you won't learn in the textbook.
I'll post one lesson at a time, each time adding some code and explaining what it does. Once all questions are answered I'll post another one, until the entire script is completed.
The first homework assignment is to open up the built-in Python console in CivIV. First you enable cheat mode in the Civilization4.ini file. Then you figure out what shortkey opens up the console. On a US keyboard it is supposedly shift + ~ but that doesn't seem to be true for other keyboard layouts. (On my Swedish keyboard its shift + ö.)
You know that you have found it if it says "Python 2.4.1" - if it doesn't then that's not it. (There are other consoles and tools also.) I believe that the shortkey to open the Python console always include the shift key though, so non-US modders could just try all keys together with the shift key...
![Roll Eyes :rolleyes: :rolleyes:](/data/assets/smilies/rolleyes.gif)
To test the Python console you write the following line on the command prompt:
Code:
print "Hello World!"
![good job :goodjob: :goodjob:](/images/smilies/goodwork.gif)
Code:
print (1 + 2) * 3 / 2
We'll use the Python console in the first lesson and again at the end of the course. You can of course follow the tutorial even without using the console, but then you won't be able to join in on the fun.
![Big Grin :D :D](/data/assets/smilies/biggrin.gif)