Editing Civilization IV/Python Tutorial

From StrategyWiki, the video game walkthrough and strategy guide wiki

You are not logged in. Please consider registering an account. By having a StrategyWiki account, you can have your own user page, upload images for your guide, and even customize the look of the site to match your tastes! Also, another benefit of registering an account is that your IP address is not logged whenever you edit, so it adds security and privacy as well. Sign up today! It takes less than one minute and requires no personal information — you're not even required to provide an e-mail address!

If you choose not to register, don't worry! You can still edit StrategyWiki all the same, just with fewer luxuries than registered users have. Your IP address will be recorded in this page's edit history, you must use the Show Preview feature to check over your work before being allowed to save your changes, and your edit may be scrutinized a bit more than that of a registered user's edit. If you don't wish any of the preceding things to happen to you or your edit, please log in or register. Please make sure that you are following all applicable policies and guidelines when making your edit, and we hope that you continue to contribute to StrategyWiki in the future!

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
{{drivel}}
{{drivel}}
{{Header Nav|game=Civilization IV}}
{{Header Nav|game=Civilization IV}}
Python can be used to modify the behavior of Civilization IV, and is essential if you want to create a new game. This tutorial for python originated from the [http://forums.civfanatics.com/showthread.php?t=154130 Civilization Fanatics Center forum], and will provide basic information on how to modify the game.
Python can be used to achieve a surprising amount of things in Civ 4, but only if you know how. Now, while I'm probably not the best person to be writing this tutorial, I feel I am quite familiar with the sort of things you can do to the game with it. Please feel free to edit anything I've got here, as the tutorial is far from complete. The tutorial is also on CFC [http://forums.civfanatics.com/showthread.php?t=154130| here]. Any updates on the wiki I will attempt to update there, though obviously the format is a bit stricter there.


For an overview of Python, you will need to check [http://www.python.org the python website], and the [[wikipedia:Python_programming_language|the wikipedia entry]]
If you want to know a little bit about python, I'd check out [http://en.wikipedia.org/wiki/Python_programming_language| the wikipedia entry] and [http://www.python.org| the python website]


Python can be used to:
Just a brief rundown on what python is capable of in Civ 4 terms:
* Make complex scripts causing events to happen on a trigger. For example, you can make it so that if you take the holy city of a religion, all Civs following that religion will declare war on you.
* Edit the interface. Pretty much all of the game interface is generated dynamically by python, and can be edited in python. You can make new buttons, alter the layout of the Civilopedia, change the way the tech tree is generated... and even radical changes such as a small dancing pig in the corner of your screen, with music. There are limitation to this - mouseover texts, for example, are far better suited to the SDK.
* Generate new map types. I haven't tried this myself, so it might not be covered too well in this tutorial.
* Edit the AI behavior. However, the SDK may be more suitable for this task.


Python can't be used exactly how you might want to use it. While the amount of things you can do in it is quite large, there are limitations on Python section of the code.  
'''Python can:'''
* be used to make complex scripts causing events to happen on a trigger. For example, you can make it so that if you take the holy city of a religion, all Civs following that religion will declare war on you.
* be used to edit the interface. Pretty much all of the game interface is generated dynamically by python, and can be edited in python. You can make new buttons, alter the layout of the Civelopedia, change the way the tech tree is generated... and even, if you so desire make a small dancing pig in the corner of your screen - with music (though I don't believe anybody has tried this, I'm pretty sure it's doable). There are limitation to this - mouseover texts, for example, are far better suited to the SDK.
* be used to generate new map types. I haven't tried this myself, so it might not be covered too well in this tutorial.
* be used to edit the AI... I'd do it with the SDK though, as it'll probably save a lot of time!


Additional tutorials for programming Python on general include [http://sthurlow.com/python/ GBM's python tutorial], which gives a brief outline of how to program in python.
'''Python can't:'''
* be used exactly how you might want to use it. While the amount of things you can do in it is really quite large, there are several things you just can't do. This is really quite annoying, but it's something you've got to learn to live with. The amount of things you ''can'' do is staggering, so don't complain. Hopefully with the release of the SDK more experienced coders will enhance the ability of python to change the way the game works.


Another simple tutorial for beginners is [https://www.techbeamers.com/python-tutorial-step-by-step/ Python tutorial - Learn step by step] to learn elementary to advanced concepts of Python.
Still reading? Good!
 
Now my suggestion for first steps would be to browse through [http://sthurlow.com/python/ GBM's python tutorial], which gives a brief outline of how to program in python. Also, if you have not done so, check out [http://www.python.org the python website] which has lots of information about python (unsurprisingly). Finally, I'd check out [http://modiki.apolyton.net/index.php?title=Guide_to_Python_in_CIV this python tutorial ''by Jon (Trip) Shafer, Firaxis''], who's tutorial you may find better than mine, after all, he is the guy who coded a lot of it in the first place.
Please note that all contributions to StrategyWiki are considered to be released under the Creative Commons Attribution-ShareAlike (see StrategyWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here. You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel Editing help (opens in new window)

Notice to contributors: The StrategyWiki administration does not condone plagiarism or the use of materials from any other source. Period. By saving this page you are promising us that you wrote this yourself, or copied it from a public domain or similar free resource. With the exception of official media (screenshots, artwork, symbols, etc., but not text) and materials released under the CC-BY-SA you must have the rights to or ownership of all work you submit to StrategyWiki. Do not copy text or images from other websites without permission. They will be deleted.

Copy and paste: – — ° ′ ″ ≈ ≠ ≤ ≥ ± − × ÷ ← → · §   Cite your sources: <ref></ref>


{{}}   {{{}}}   |   []   [[]]   [[Category:]]   #REDIRECT [[]]   &nbsp;   <s></s>   <sup></sup>   <sub></sub>   <code></code>   <pre></pre>   <blockquote></blockquote>   <ref></ref> <ref name="" />   {{Reflist}}   <references />   <includeonly></includeonly>   <noinclude></noinclude>   {{DEFAULTSORT:}}   <nowiki></nowiki>   <!-- -->   <span class="plainlinks"></span>


{{Header Nav|game={{subst:BASEPAGENAME}}}}   {{Footer Nav|game={{subst:BASEPAGENAME}}|prevpage=|nextpage=}}   {{spoilers}}   {{spoiler|}}   {{delete|Unused}}   {{rename|MS Monster .png}}   {{floatingtoc}}   {{stub}}


Symbols: ~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶   # ∞   ‘ ’ “ ” ‹› «»   ¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ № ₧ ₰ £ ៛ ₨ ₪ ৳ ₮ ₩ ¥   ♠ ♣ ♥ ♦   ♭ ♯ ♮   © ® ™
Latin: A a Á á À à  â Ä ä Ǎ ǎ Ă ă Ā ā à ã Å å Ą ą Æ æ Ǣ ǣ   B b   C c Ć ć Ċ ċ Ĉ ĉ Č č Ç ç   D d Ď ď Đ đ Ḍ ḍ Ð ð   E e É é È è Ė ė Ê ê Ë ë Ě ě Ĕ ĕ Ē ē Ẽ ẽ Ę ę Ẹ ẹ Ɛ ɛ Ǝ ǝ Ə ə   F f   G g Ġ ġ Ĝ ĝ Ğ ğ Ģ ģ   H h Ĥ ĥ Ħ ħ Ḥ ḥ   I i İ ı Í í Ì ì Î î Ï ï Ǐ ǐ Ĭ ĭ Ī ī Ĩ ĩ Į į Ị ị   J j Ĵ ĵ   K k Ķ ķ   L l Ĺ ĺ Ŀ ŀ Ľ ľ Ļ ļ Ł ł Ḷ ḷ Ḹ ḹ   M m Ṃ ṃ   N n Ń ń Ň ň Ñ ñ Ņ ņ Ṇ ṇ Ŋ ŋ   O o Ó ó Ò ò Ô ô Ö ö Ǒ ǒ Ŏ ŏ Ō ō Õ õ Ǫ ǫ Ọ ọ Ő ő Ø ø Œ œ   Ɔ ɔ   P p   Q q   R r Ŕ ŕ Ř ř Ŗ ŗ Ṛ ṛ Ṝ ṝ   S s Ś ś Ŝ ŝ Š š Ş ş Ș ș Ṣ ṣ ß   T t Ť ť Ţ ţ Ț ț Ṭ ṭ Þ þ   U u Ú ú Ù ù Û û Ü ü Ǔ ǔ Ŭ ŭ Ū ū Ũ ũ Ů ů Ų ų Ụ ụ Ű ű Ǘ ǘ Ǜ ǜ Ǚ ǚ Ǖ ǖ   V v   W w Ŵ ŵ   X x   Y y Ý ý Ŷ ŷ Ÿ ÿ Ỹ ỹ Ȳ ȳ   Z z Ź ź Ż ż Ž ž   ß Ð ð Þ þ Ŋ ŋ Ə ə   {{Unicode|}}
Greek: Ά ά Έ έ Ή ή Ί ί Ό ό Ύ ύ Ώ ώ   Α α Β β Γ γ Δ δ   Ε ε Ζ ζ Η η Θ θ   Ι ι Κ κ Λ λ Μ μ   Ν ν Ξ ξ Ο ο Π π   Ρ ρ Σ σ ς Τ τ Υ υ   Φ φ Χ χ Ψ ψ Ω ω   {{Polytonic|}}
Cyrillic: А а Б б В в Г г   Ґ ґ Ѓ ѓ Д д Ђ ђ   Е е Ё ё Є є Ж ж   З з Ѕ ѕ И и І і   Ї ї Й й Ј ј К к   Ќ ќ Л л Љ љ М м   Н н Њ њ О о П п   Р р С с Т т Ћ ћ   У у Ў ў Ф ф Х х   Ц ц Ч ч Џ џ Ш ш   Щ щ Ъ ъ Ы ы Ь ь   Э э Ю ю Я я   ́
IPA: t̪ d̪ ʈ ɖ ɟ ɡ ɢ ʡ ʔ   ɸ β θ ð ʃ ʒ ɕ ʑ ʂ ʐ ç ʝ ɣ χ ʁ ħ ʕ ʜ ʢ ɦ   ɱ ɳ ɲ ŋ ɴ   ʋ ɹ ɻ ɰ   ʙ ⱱ ʀ ɾ ɽ   ɫ ɬ ɮ ɺ ɭ ʎ ʟ   ɥ ʍ ɧ   ʼ   ɓ ɗ ʄ ɠ ʛ   ʘ ǀ ǃ ǂ ǁ   ɨ ʉ ɯ   ɪ ʏ ʊ   ø ɘ ɵ ɤ   ə ɚ   ɛ œ ɜ ɝ ɞ ʌ ɔ   æ   ɐ ɶ ɑ ɒ   ʰ ʱ ʷ ʲ ˠ ˤ ⁿ ˡ   ˈ ˌ ː ˑ ̪   {{IPA|}}

Your changes will be visible immediately.
  • For testing, please use the sandbox instead.
  • On talk pages, please sign your comment by typing four tildes (~~~~).

Please note:
  • If you don't want your writing to be edited mercilessly or redistributed by others, do not submit it.
  • Only public domain resources can be copied without permission — this does not include the vast majority of web pages or images.
  • See our policies and guidelines for more information on editing.

This page is a member of a hidden category: