Python Help...

tsentom1

Bubble Dragon
Joined
Jul 24, 2007
Messages
1,000
Location
New York
Okay, I have most of it figured out just the last step I don't know how to code:

[TAB][TAB][TAB][TAB]for iCity in range( len( lCities ) ):
[TAB][TAB][TAB][TAB][TAB]pCity = lCities[ iCity ]
[TAB][TAB][TAB][TAB][TAB]pCity.changeCulture( 10 )

Okay, so this has that cities in the range get 10 more culture, correct? (There's stuff before this, this is merely the end of the coding).

[TAB][TAB]if city.getNumRealBuilding(gc.getInfoTypeForString("BUILDING_A")):

That asks if the ctiy has building A, correct?

I just need to combine them, so in the final code for cities in the range, only if they have a building change the cities culture but every time I try it doesn't work. (If I don't try to include the building part it does work so it's only this part.

Can someone help me with this last step?
 
Shouldn't you state how many of building A the city has? That is, 1?

In this case that's doesn't matter . "if city.getNumRealBuilding(gc.getInfoTypeForString("B UILDING_A")):" does the same at "if city.getNumRealBuilding(gc.getInfoTypeForString("B UILDING_A")) >0 :" (0=False , and (i>0)=True) . Perhaps pCity instead of city ? Do you have logging enabled and no error ?

Tcho !
 
I just need to combine them, so in the final code for cities in the range, only if they have a building change the cities culture but every time I try it doesn't work.

This is the point where you should have posted the actual code you're using that doesn't work. Describing what you've done isn't as helpful to us. In any case, Sto probably nailed it given the code you did post.

BTW, you can simplify your loop by iterating over the cities directly, rather than the index into the list. Also, while it may provide only a minor speed benefit, it's a good idea to save values you're going to look up multiple times, especially in a loop like this.

PHP:
eBuilding = gc.getInfoTypeForString( "BUILDING_A" )
for pCity in lCities:
    if pCity.getNumRealBuilding( eBuilding ):
        pCity.changeCulture( 10 )
 
Hey, thanks for the help it worked!!!!!

Sorry about not posting the code entirely. I had coded it for something else and then decided to add it to check for the building and was unsure of how to insert it, not so much bad coding, and was wondering if "if city.getNumRealBuilding(gc.getInfoTypeForString("B UILDING_A"))" was correct code, so to speak, since it wasn't working. I didn't even realize I didn't have pCity.

Thanks again:)
 
Back
Top Bottom