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

Modding help

Discussion in 'Civ4 - Rhye's and Fall of Civilization' started by fattythefat, Mar 22, 2010.

  1. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    Anybody know some superb guide on how to learn to mod? I would really want to learn to mod. Know this aint the perfect forum for this thread, but i especially want to learn how to mod stability and spawn dates and such... It would be great if somebody could post a link or two:)
     
  2. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,080
    Location:
    In orbit
    Check the tutorials. ;)
     
  3. Úmarth

    Úmarth Megalomaniac

    Joined:
    Jun 28, 2007
    Messages:
    1,184
    Location:
    United Kingdom
    Well there aren't any tutorials specifically for modding RFC or for replicating its features as far as I know. I think your best bet, assuming you're starting from scratch, would be to read a general introduction to Python syntax and then dive right in and see if you can figure out Rhye's code. I find learning by doing is always better when it comes to programming.
     
  4. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Yeah, you should learn a programming language, and continue from there. Python would be a very good place to start. :D

    I've found that this is a great start for basically learning the all there is to know. Its a textbook and not in any way CivIV specific, but most of the stuff still apply. Also, the CivIV API will start to make a whole lot of sense if you know Object-Oriented Programming, as it's called. Here's another beginners guide.

    Once you know Python you can move up to C++ and actually modify the DLL file. This is a step I'm yet to take myself, as I'm still learning Python.
     
  5. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    Thanks! Ill start reading now :)

    EDIT: how do i create a python file?

    Edit2: Downloaded a Python 3.1.2. In the guide it says that i shall type this:
    print "Hello, World!"

    and this should come out:
    Hello, World!
    But when i press enter the last " glows red and it says synthax error... what am i doing wrong?
     
  6. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Good for you! :goodjob: It will take some time and effort, but it will be worth it in the end. Don't get bogged down but try to get through the textbook - there will be those eureka! moments down the line, when you suddenly realize how - or why - something works. So don't worry about everything not being crystal clear at first.

    Also, if you're any good at math - that helps a lot. Partly because computer programming is basically logics and applied mathematics. And partly because textbooks on the subject will be written by computer scientists, and these people know math and use it in examples. :rolleyes:

    Personally I'm no good at math, so this is quite hard for me. :p

    First of all, there are two ways to program a computer. The first option is what the textbook will start with, and that is using an interpreter and write your code into the command line, line by line and get the results immediately. This method should be good for learning and experimenting with code.

    The second option is scripting, and at least in Python you create Python files, or "modules". You can use any text editor of your choice and by convention you don't name modules ".txt" but ".py". You will be using modules once you make your own mods - or when you mod other people's mods.

    I believe CivIV uses Python v2.4 so you could pick that up instead...

    I'm yet to use Python outside of CivIV as I never bothered with the basics when I started modding RFC. This was a mistake but this also means that I'm yet to use the Python interpreter myself (except the built-in interpreter in CivIV).

    I guess I should do that now. :rolleyes: If I can figure out where to download and how to install...
     
  7. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    How do i open the Built-in python... Somebody told me it was the ~key but it didnt work... Im using a danish keyboard, and i know that it is different... As an example:
    When i tried to start modding Medieval TW 2 it wasnt the ~ but the Æ key... The Æ key doesnt work here...
     
  8. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    it works with the 2.4 version... but still cant find the key to open the inbuilt python
     
  9. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Update: I installed Python 2.6 and tested the tutorial program ("Hello World!"). It works, so I wouldn't know what the issue could be. A "Syntax Error" occurs when you don't follow the syntax of the programming language, like if you fail to include a second quotation or parenthesis, misspell a command or not make any sense the to interpreter in some other way. The interpreter will only interpret - it will not try to guess what you're trying to say.

    If you haven't solved this problem yet, post a screen caption and we'll have a look at what's happening. (Hit the "Print Screen" key and paste the captured image into Paint or any other application like that. Save the image and attach to a post.)

    You could alternatively try this little program on for size. First line:
    Code:
    x = 42
    Second line:
    Code:
    print x
    The interpreter should now tell you the meaning of Life, the Universe and Everything. ;) In that case the problem is most likely the quotation marks themselves - try simple quotation (') instead. ('Hello World!')
     
  10. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I find that beast to have a less than useful interface, but on my (Swedish) keyboard I think the key is "ö" or "ä" or something like that. Also know that there are two different interpreters (or whatever) and only one works. :rolleyes: You might have to hold down the shift key or something to open up the right one. (The working one states "Python v2.4" or something like this above the command line.)

    Sorry for being able to be any more helpful on this. :(
     
  11. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    A quick note on the print command:

    Since CivIV is a non-text-based game you can't use "print" to show any kind of text in the game interface. Instead you can use it to write stuff into the Python Debug Log, which is very handy while designing your mod.

    Disclaimer: This way of printing out debug messages work at least in the RFC modules/files, and you can find many examples of this in Rhye's code. (I don't know if you need to use parenthesis or not, though. I've used then myself, even if they might not be required for simple messages or messages only containing a string.)

    edit: If you're experimenting with the built-in interpreter you can of course use "print" to get readouts inside the interpreter.
     
  12. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    A quick one on whitespace:

    Python is very particular about indentation. You organize your modules into blocks of code, and each block makes up a "level" in the indentation. I've learned that CivIV code mostly uses tabs as whitespace for indentation, but note that Rhye only uses blank spaces! (8 blank spaces to be exact - nothing more and nothing less.) So if you're adding code to any of his work you must also use blank spaces. You can't alternate between different types of whitespace in a single module, or so I believe.

    Also, whitespace (blank spaces) in code is mostly optional and you can get away with a lot. But it is prudent to follow one single format in your code, so that the code is easier to read. So you could write this bit of code:
    Code:
    x = 42
    if x == 42:
            return x - 1
    Or format it like this:
    Code:
    x=42
    if x==42:
            return x-1
    I think that the first example is more readable, though.
     
  13. jmerry

    jmerry Chieftain

    Joined:
    Jan 21, 2010
    Messages:
    122
    If you don't like the eight-space mode, try a global search/replace of that to tabs. In the text editor I've been using, those show up as the exact same size.

    The one feature my editor doesn't have that I wish it did? Line numbers. When debugging, the error log includes line numbers, and making those easier to find would be nice.
     
  14. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    The print command worked... But now the guide says i should try to add a note to a function ( like hour = minute*60) and it says i should add a # and then the note, but the note and the # just turns red... Tried ALL the keys on my keyboard none opened the inbuilt python in civ...
    Edit: your return function doesnt function either... im doing something wrong but im making progress :)
     
  15. jmerry

    jmerry Chieftain

    Joined:
    Jan 21, 2010
    Messages:
    122
    Uh- the # is a comment marker; anything after it on the line is ignored by the parser. It has nothing to do with how the program works, and comments are only there for human readability.
     
  16. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Its a bit unclear what the actual instruction said, but unless you get a error message I'd say everything is peachy. As jmerry said, the # sign isn't really a part of the programming language, so that would probably explain why the interpreter marks it red. (It does so on my copy of the IDLE interpreter also.)

    Then its a sign that requires shift or alt, but refer to the page on keyboard layouts on Wikipedia (I didn't bookmark the link back when I was having the same issue) to figure out what key replaces what key. Note that you also need to figure out what keys are the parenthesis, brackets, quotations and so on - because they most likely won't be the keys displayed on your keyboard... :rolleyes:

    If you plan on using the built-in interpreter you could just as well get a English/US keyboard... :p

    Ah, that was just to illustrate the difference in syntax. :D The return statement is used to override the default return value of a function (or method, as they are known in Object-Oriented Programming) and thereby exit the function. If the textbook haven't covered functions yet it should do so shortly.

    Keep the questions coming so that you don't get bogged down. :king:
     
  17. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    in the guide it said i should use the sin function... There aint any...
    Edit: I also tried with alt gr and shift
     
  18. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I'm not sure what you mean... Maybe you could post a link to or a quote to the passage in the textbook you're trying to decipher. Otherwise it can be hard to know what the issue could be.

    If you mean a mathematical function in Python, then I believe that you need to import a math module and use dot notation when you use the function/method, like:
    Code:
    import math
    math.sin(value)
    (The variable "value" would be a numerical value.)
     
  19. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    yeah it was written some lines below...
    Now i have this problem. it says thisHere is an example of a user-defined function that has a parameter:

    I did like this :
    def printTwice (bruce) :
    print "bruce", "bruce"
    printTwice ("bruce")
    then it says this:
    bruce bruce
    then i do this:
    printTwice ("spam")
    it shows this:
    bruce bruce
     
  20. fattythefat

    fattythefat Chieftain

    Joined:
    Feb 4, 2010
    Messages:
    39
    Finally progress came over the printTwice thing by doing this
    printTwice (bruce) :
    print bruce, bruce
    printTwice ("bruce")
    def printTwice (spam)
    print spam, spam
    printTwice ("spam")
    and then it showed:
    spam spam
    :)

    Edit:Cant understand this...:
    how do i use the traceback function? He doesnt explain how...
     

Share This Page