Customizing City Names Maps

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.
 
Is anyone willing to give me a few pointers so that I can resolve the problem and still use my modified City Name Map?
You could have missed "," or something else.
I don't think we can help you if you won't upload this file. ;)
 
Also make sure your indentations (whitespaces) are correct. Python is very sensitive when it's not given enough indentations :)
 
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.

Also make sure your indentations (whitespaces) are correct.
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?
 

Attachments

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.
 
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.
 
Also make sure your indentations (whitespaces) are correct. Python is very sensitive when it's not given enough indentations :)

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.
 
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.
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 ;)
 
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.
 
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 :)
 
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.
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.
 
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.)
 
Back
Top Bottom