Syntax help

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
Learning Python, doing the tutorials on the Let's learn to mod CIV today thread. Otherwise all I've done before this is XML editing, like adding units, modifying religions, that sort of thing. I really like the revolutions mod, unfortunately though the Distance modifier was just unplayable as coded, so I'm tinkering with it to get it to work well (which has forced me to learn python).

First I edited the code to this:
Code:
            # Distance to capital - 4, max 13
            cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
            cityDistModifier = min([cityDistModifier, 100]) - 3
after much trial and error figuring out a bunch of mistakes. This gave me the intended behavior.

Next step was to add in a function to see if the city was connected to the capital and give it a penalty if it was not. After much failed attempts I got this:
Code:
            # Distance to capital - 4, max 13
            cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
            cityDistModifier = min([cityDistModifier, 100]) - 3
            if( not pCity.isConnectedTo(capital) ) :
                cityDistModifier = 2*cityDistModifier
            else:
                cityDistModifier = cityDistModifier
To work as intended

The next step is to add in technology modifiers, so as new communication technologies become available (such as the wheel, railroads, radio, etc.) the distance revolt penalty is further reduced. Found a tech reference in the original code, and copied it, just to see if it would work (later I will change the tech names to match), and currently have this:
Code:
            # Distance to capital - 4, max 13
            cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
            cityDistModifier = min([cityDistModifier, 100]) - 3
            if( not pCity.isConnectedTo(capital) ) :
                cityDistModifier = 2*cityDistModifier
[B]            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iNationalismTech) )
                cityDistModifier = cityDistModifier/2[/B]
            else:
                cityDistModifier = cityDistModifier
Unfortunately using this the revindex box does not show up in the cities. This means my python is broken. So what would be the proper syntax?
Also what's the standard naming convention for techs in python? Is it The_WheelTech or what?
 
Edited with new syntax problem. I figured out the first one I posted.

Edit: Got it, forgot a :
 
Just a note, you can drop the else part of your if statement.
Code:
           else:
                cityDistModifier = cityDistModifier
cityDistModifier by nature equals it self, so why tell it to equal it self all over again? And you can have just an if, or an if with only 60 elifs, you don't have to have the else. If you would like to be more explicit and put the else so that others know you didn't forgot to put it use the pass statement.
Code:
else:
                pass
Never mind me, and keep up the good work, someday you'll be able to do it all in a matter of a couple minutes.
 
Nahh, I can't pull that out, it's a catch all that slips through the cracks.
 
I have to agree with Zebra, that else statement isn't doing anything and can be left out.
 
Back
Top Bottom