1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Python (civ4 scripting language) tutorial thread

Discussion in 'Civ4 - Modding Tutorials & Reference' started by Gingerbread Man, Aug 16, 2004.

  1. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Go to my python tutorial website for updated versions of all the lessons posted in this thread. The site also contains some other things that may be useful for your Civ Python modding adventures, so feel free to have a look, and ask questions in this thread if they arise.

    Lesson Index:
    (Opens in a new window. Post number Next to link)
    Lesson 1 - What is Python, and how do I install it? Post 25
    Lesson 2 - One-liners - very simple 'programs' Post 43
    Lesson 3 - Programs in a file, and variables Post 70
    Lesson 4 - Loops, Loops, Loops, Loops, Loops, Loops... Post 85
    Lesson 5 - Oh, how functional! Post 105
    Lesson 6 - Tuples, Lists, and Dictionaries Post 120
    Lesson 7 - another loop, and a simple game Post 134
    Lesson 8 - Let the classes begin! Post 153
    Lesson 9 - 'Borrowing Other People's Stuff (with Modules) Post 187
    Lesson 10 - File I/O Post 189
    Lesson 11 - Exception Handling: dealing with the dumb Post 197

    Firaxis made a daring and interesting move when they announced that much of the modding in cIV will be in Python and XML. Python is a well established language that is well known among server-side scripting and open-source communities. XML is a relatively new markup language, often mistaken for something like HTML, but actually has an entirely different purpose.

    with Firaxis making this move, the civ modding community has an unprecidented opportunity - they can learn the modding language before the game evn comes out!

    So, I'm thinking, with at least a year until cIV comes out, we should start learning python an XML now! By learning python, and focusing on the logic aspects of it that will be used in the AI, we may only need a slight learning curve to adapt it to cIV.

    Here, I am periodically posting very easy, interactive, tutorials in python. Anybody can join, from a person with no programming experience, to a full-blown professional developer. Python and XML are both free, and easy to obtain.

    And remember - This is a living tutorial, not some lifeless, static text book. Ask questions, share thoughts, grow your knowledge!
     
  2. ybbor

    ybbor Will not change his avata

    Joined:
    Nov 16, 2003
    Messages:
    5,773
    Location:
    Chicago Suburbs
    uhh, well i guess, i don't know, i;ll try, but i'll probably give uo, i know a bit of HTML abd that's it
     
  3. Mr. Will

    Mr. Will Mister

    Joined:
    Jan 30, 2004
    Messages:
    475
    Location:
    Simpsonville, SC
    Mr. Will - Dab of HTML, Dab of BASIC :lol: , Attempted Visual Basic
     
  4. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Wow, excellent response!

    ybbor - that's fine, just give it a go, just do as much as you can.
    Mr. Will - great to have you on board.
     
  5. Gogf

    Gogf Indescribable

    Joined:
    Oct 12, 2003
    Messages:
    10,163
    Location:
    Plane Of Fish Sticks
    I'll join. I know some HTML.
     
  6. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    I welcome Gogf to the team!
     
  7. warpstorm

    warpstorm Yumbo? Yumbo!

    Joined:
    Dec 19, 2001
    Messages:
    7,688
    Location:
    Snack Food Capital of the World
    Extensive professional Python programming as well as use of XML for data storage. I don't know how much I'll be able to participate though...

    To get started on this go to www.python.org for details on Python. If you know nothing about Python start here http://www.python.org/topics/learn/ This has links to excellent tutorials for all levels of programmers (including those who have never programmed before).

    Go to http://www.python.org/2.3.4/ to get the latest version of Python. You may also want to get the win32all package for it. This is a Windows specific IDE that is very good.
     
  8. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Alrighty!
    Thanks warpstorm for the links. I found that site, though didn't know if it was good or not.

    As for your participation, do as much as is convenient for you. I was hoping for somebody with professional skills, to help us along when we get stumped. Just your prescence should make it easier.
     
  9. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    Be able to or want to? ;) :)

    I suppose I'll join up. I know VB, C++, some C, some XML and some Python (I don't count HTML as a real language ;)).
     
  10. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Welcome aboard, Trip! It's great to have people with previous knowledge help.

    When this starts, should we move it to the Computer Talk forum, or leave it here? I figure seeing it will be civ-focused, it should stay, but that will be a decision for the mods.
     
  11. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    Oh, I know Java also. Almost forgot about that. That and I know HTML and BASIC quite well, if you want a complete list of my knowledge.
     
  12. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    By the way, I think this is a really good idea. Having a communal learning effort is a really good idea, it'll help me as I continue to learn Python and how it is similar and differs from the other languages I know. ;)
     
  13. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Yeah, this will also be really good for my software classes that I am starting in school next year. They dont actually teach you a language - you have to pick one, learn it, and apply the theory you learn in class to a program you make. I figured I'd learn python with you guys who will probably be interested in learning it for cIV, and kill two birds with one stone :D
     
  14. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    Clever, I like the way you think. ;)
     
  15. Coorae

    Coorae Chieftain

    Joined:
    Feb 19, 2003
    Messages:
    108
    Location:
    computer
    I want to join
    I have 3 years expreience in C++ and VB and Blitz. I know some java and html.
    I dont know what xml or python is though.
     
  16. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Welcome aboard Coorae!

    Never heard of Blitz. What is it?

    Python is described at www.python.org
    Dont know where XML is decribed, though.
     
  17. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    There's a FAQ here, but it mostly describes XML's application in an internet-based environment.

    http://www.ucc.ie/xml/

    For CIV it will be used to store variables of various sorts that modders can change in order to create mods/scenarios.
     
  18. MMAfan

    MMAfan Chieftain

    Joined:
    Aug 4, 2004
    Messages:
    15
    JAVA, education.
    Pascal, education (yak! :thumbdown )
    C, I used to program my college student exercises.
    C++, well know the syntax.
    Perl, programmed some part for a system that track positions with GPS.
    XML, used it in above system.
    HTML, I know how to echo it from a php file. :blush:
    JAVASCRIPT, JSCRIPT ASP.
    PHP, using it right now.

    Oh and I love to discuss AI architecture and design :)

    Havent got much time to teach.. I am a bad teacher anyway ;)

    Now where is the thread where we start designing the AI?? :goodjob:
     
  19. Gingerbread Man

    Gingerbread Man Dark Magus

    Joined:
    Jun 9, 2002
    Messages:
    2,078
    Location:
    Ooorstrailier!
    Welcome MMAfan!

    I'll be starting the thread where we learn Python in about 24hrs - we need to give other people the opportunity to join.

    We'll start programming AIs as soon as we are fluent enough in Python. I think we might make a very simple game (no more complex than pong) and make an AI for that as a start. Once we get that, we'll move up to another level. But that will be a while - some of us haven't learnt python at all yet.
     
  20. Chieftess

    Chieftess Moderator Retired Moderator

    Joined:
    Feb 10, 2002
    Messages:
    24,160
    Location:
    Baltimore
    I'll join up. Make a nice tutorial thread, and I'll sticky it.
     

Share This Page