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

Customizing City Names Maps

Discussion in 'Civ4 - Rhye's and Fall of Civilization' started by Science Rules, Apr 21, 2010.

  1. Science Rules

    Science Rules Prince

    Joined:
    Nov 26, 2004
    Messages:
    358
    Location:
    Massachusetts
    I got inspired by recent discussions to modify my copy of the CityNameManager.py file so that I could play with the city names that I prefer. Others have said that all one needs to do is find the array that stores of the city names and change those values, which is what I did. I added French City names for the rest of North America and I expanded the Dutch City name map a little. However, now every single time I start a new game I lose on the very first turn, so I obviously did something wrong. Is anyone willing to give me a few pointers so that I can resolve the problem and still use my modified City Name Map?

    I didn't modify the if statements that control city renaming on city conquest.
     
  2. TimeShifter

    TimeShifter Chieftain

    Joined:
    Sep 1, 2009
    Messages:
    46
    Location:
    Russia
    You could have missed "," or something else.
    I don't think we can help you if you won't upload this file. ;)
     
  3. nody

    nody Emperor

    Joined:
    Nov 28, 2004
    Messages:
    1,168
    Location:
    Noviomagus, Batavia
    I think ít crashed because Rhye don't want us to mess with his mod. :lol:
     
  4. Leoreth

    Leoreth Prince of Blood Moderator

    Joined:
    Aug 23, 2009
    Messages:
    34,496
    Gender:
    Male
    Location:
    House of Hades
    Also make sure your indentations (whitespaces) are correct. Python is very sensitive when it's not given enough indentations :)
     
  5. Science Rules

    Science Rules Prince

    Joined:
    Nov 26, 2004
    Messages:
    358
    Location:
    Massachusetts
    Oops, I thought I had uploaded the py file, but I didn't know that .py files aren't allowed by civfanatics. Here's the file, which I zipped in order to put it into an acceptable format.

    I used Excel to modify the names and I don't believe Excel depicts the indentations.
    So that might be the problem. Is there a different piece of software that is better at modifying python files? I think Notepad would work, but are there others?
     

    Attached Files:

  6. Leoreth

    Leoreth Prince of Blood Moderator

    Joined:
    Aug 23, 2009
    Messages:
    34,496
    Gender:
    Male
    Location:
    House of Hades
    After line 1939, many lines begin with a quotation mark. I don't know where they come from, maybe caused by Excel for some reason. I suggest use simply use Notepad for editing and Excel only for reference to avoid such errors.
     
  7. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Also, if you're modding Python, you need to enable debugging.

    Note: You really need to do this. If you don't, someone else will have to do it for you. I don't see how that would be justified.
     
  8. duckstab

    duckstab Child of Noble Family

    Joined:
    May 5, 2008
    Messages:
    1,447
    Gender:
    Male
    Location:
    Austin, Texas
    I once had a job writing Python and I despised this aspect of the language. One especially insidious problem is when tabs and spaces accidentally get mixed in the same file - the interpreter can get completely confused.

    @Science Rules: python.org has a pretty exhaustive list of editors here. Pick your poison. I'd recommend one that does syntax highlighting at least, it'll save you a lot of headaches if you mistype something.
     
  9. killerkebab

    killerkebab Prince

    Joined:
    Jun 25, 2009
    Messages:
    571
    Definitely do this. Poor Baldyr helped me out and I can just imagine him now, pulling his hair out and screaming at a typo or some other stupid mistake ;)
     
  10. Science Rules

    Science Rules Prince

    Joined:
    Nov 26, 2004
    Messages:
    358
    Location:
    Massachusetts
    I'm enabling debugging & I'm downloading a quality python editor now, so I don't want anyone to burden themselves by looking for my typos until I've had a chance to look myself this weekend.

    Thank You everyone for the the general bits of advice. My only programming experience is with Fortran and a little bit of C++; so I really don't know much about the syntax for python.
     
  11. killerkebab

    killerkebab Prince

    Joined:
    Jun 25, 2009
    Messages:
    571
    I recommend SciTE - this editor can go through your file looking for indentations and disable tabs. It will even replace all tabs with spaces in the file :)
     
  12. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    We've all been there. (The cause for my own initial troubles was probably a single typo somewhere among all the changes I had done. And once an "exception" is raised it makes the Python translator throw out the whole thing. With debugging enabled, I would have seen the exception and been able to debug.)

    I use IDLE for all my Python needs. It is the default translator available from Python.org that ships with the Python language itself - and also has a built-in editor. The translator is very useful for testing statements and getting your syntax in order, and the editor is very handy for handling indentation and the like. Also, it can check your modules (.py files) for syntax before you load them into CivIV - and potentially get an exception. (Menu/Run/Check Module)

    There might be other editors out there, but I think IDLE offers a good balance of features contra complexity. Its quite basic, actually.
     
  13. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    About Python syntax:

    Indentation determines flow and works with blocks of code. And every level if indentation must be equal in length. You can choose between blank space or tabs, but since Rhye uses blank spaces you have to also. In fact, Rhye uses eight blank spaces - this means that the first level is zero blank spaces, the second one is 8, the third 16 and so on. (A good Python editor will let you define the amount and type of whitespace you wanna work with and then you use the tab key to move up one "level".)

    Example:
    Code:
    iVariable = 0
    while iVariable != 42:
            print (iVariable, "wrong number!")
            iVariable += 1
    print ("right answer:", iVariable)
    The code starts on "module level", also known as __main__. The while command creates a loop and the colon at the end of line #3 indicates that a new block of code should be inserted. This is why the following two lines - the ones that are part of the loop - are indented one level (= 8 blank spaces). The last line is not part of the loop, so it is not indented.

    So the rule is: Add one level worth of indentation after every colon.

    When to end a line with a colon? Well, any time you use a logical statement, I guess... (You don't need to indent for assignment statements, like the first line in the example. But then again, there's no colon either.)

    Just so I haven't confused anyone, this also works:
    Code:
    iVariable= 0
    while (not iVariable ==42):
        print iVariable, 
        print "wrong number!"
        iVariable = iVariable+1
    print "right answer:",
    print iVariable)
    So there are some options when it comes to syntax. Note that I only used four blank spaces for indentation and it works just the same. (But then I'm stuck with that for the entire module, or file.)
     

Share This Page