trying to use a minimalist mod to do big things

No, you cannot write to a global variable without using the global keyword to tell Python what you mean.
Aha, so a variable defined at module level can only be used as a constant then? Because you can't change the value inside the body of an function. Check.

This also means that variables defined at module level really aren't global variables at all. Sorry for adding to the confusion then. :p
 
hm...it appears that even if one beelines metal casting, it cannot be had by 1600 BC. I may need to make that another tech...
 
Aha, so a variable defined at module level can only be used as a constant then? Because you can't change the value inside the body of an function.

No, you can change a global variable as long as you tell Python that's what you mean to do.

Code:
x = 5

def setX():
    [B][COLOR="Red"]global x[/COLOR][/B]    # yes, I mean *that* x up there!
    x = 10

print x
setX()
print x

prints

Code:
5
10

You don't need the "global x" line if you only want to read x. If you assign to x without the "global x" line, it creates a new local variable called x. It doesn't matter where in the function you assign to x. This can be tricky.

First, if the function assigns to x then x is treated as a local variable. Any other access is to the local variable. Thus if you read from x before assigning to x--without the "global x" line--you will get an exception.

Code:
x = 5

def setX():
    print x
    x = 10

setX()

The above code will get an exception on the "print x" line:

Code:
UnboundLocalError: local variable 'x' referenced before assignment
>>> def setX():
	print x

This can be confusing because the rule that forces x to be local (function assigns to x) takes precedence over the rule that makes x global (function reads from x) as long as you don't tell Python you want to use the global x variable.
 
This Sign/Landmark thing is pretty sweet, actually. :D I never did consider CyEngine for this.
 
So, this won't work then:
Code:
x = 5
def setX():
    if x == 5:
        x = 10
But this will work:
Code:
x = 5
def getX():
    return x
So the name space of the function is set when the function is read the first time (imported, probably) and not when the function is executed?

This fully explains why antaine was getting the exceptions. And it was my folly all along. :p
 
I think you could post any working version in another thread in another forum if you want others to actually test it. :king:
 
hm...still having a bit of a balance issue. I've lowered the flip requirement to "if unhappiness = city population (size)" and it's still virtually impossible to keep them from flipping. Even with 3234234 military units in a level 8 city, it still shows 8 unhappy. I've checked, and it seems that every city on the map has unhappiness equal to city size or one more than the size.

I need a benchmark that will be difficult to keep from flipping, yet still be possible for a determined human to keep. It just seems that unhappiness level is right at the city size almost every time.

Anybody have any other thoughts?
 
when I wanted to make the cutoff 1/3 unhappy citizens, I meant to compare it to the number of happy citizens, not the "population" which is synonymous with "city size."

I think I just need to go back to my original idea but compare it to:
iHappy = pPotentialCity.happyLevel(0)
rather than the population.

on another note...iHappy sounds like something out of the dregs of Apple's marketing department...although, to be fair, I certainly wouldn't want to buy an iUnhappy, either...
 
It sounds like you might be looking at the wrong thing. There is a happy level and there is an unhappy level. They are separate things. As long as the happy level is more than the unhappy level the city is happy. If the unhappy level is higher then the city is unhappy and you have angry citizens who don't work. Unless you build a wonder that removes all unhappiness from a city, it will always have at least as high an unhappy level as it has population since every point of population actually causes a point of unhappiness.

You might be interested in the number of angry citizens, rather than the actual unhappy level. That is, the amount by which the unhappiness exceeds the happiness (if it does). The function pCity.angryPopulation(0) will tell you how many angry citizens who are refusing to work a city has, if it has any. Those are the very unhappy people.
 
Well, I'm hesitant to use angry citizens as they're fairly easy to keep away. Thus, no city would ever flip.

I think its just a matter of doing
Code:
				for tCoords in getPlotList((59, 43), (63, 48)):
						x, y = tCoords
						pCurrentPlot = cyMap.plot(x,y)
						pPotentialCity = pCurrentPlot.getPlotCity()
						iUnhappy = pPotentialCity.unhappyLevel(0)
						if pPotentialCity != None:
								iHappy = pPotentialCity.gethappyLevel()
								if iUnhappy *3 >= iHappy:
										pCurrentPlot.setOwner(7)

instead of my original


Code:
				for tCoords in getPlotList((59, 43), (63, 48)):
						x, y = tCoords
						pCurrentPlot = cyMap.plot(x,y)
						pPotentialCity = pCurrentPlot.getPlotCity()
						iUnhappy = pPotentialCity.unhappyLevel(0)
						if pPotentialCity != None:
								iPopulation = pPotentialCity.getPopulation()
								if iUnhappy >= iPopulation:
										pCurrentPlot.setOwner(7)

maybe even going with *4 instead of *3. I flooded my city with military units after rushing to reasarch and adopt hereditary rule. Having it be unhappy*4>happy would require a level 5 city to have 20 happy citizens to go along with the 5 unhappy ones in order to keep from flipping. Hard and expensive, but doable...
 
alright...fixed a few typos and that was it. Now, the happy citizens have to outnumber the unhappy citizens 5-1 to prevent a flip. This gives the human player a choice (if they're willing to work for it), but still ensures most of the time cities will flip if the owner is not specifically trying to prevent it.

When I originally tested the flip code, I used worldbuilder to add wonders and buildings etc. The city that stayed actually had no unhappy citizens, so I never noticed the problem until I actually played, trying to prevent it and found that I couldn't.
 
well, not that it has to be 5:1, it just has to be more than 4:1. Exactly 4:1 (like a brand new, level 1 city) will flip, but a lvl 1 city with a temple will not.

I suppose now would be the time to start making advanced starts. I'm not going to do one for every civ, but one for each spawn era (4000BC, 800BC, 300AD, and 1700AD). Some civs will still have a long <return> time (like Russia, 1000AD*), but it's not as bad as starting in 4000BC to get there.

...meh...maybe I'll do a 1000AD start, too...

*Russia is part of the medieval spawn that includes England, France, Spain, Germany and Russia. (Arabia is 700AD, but has it's own function)
 
Congrats! :king:
 
yup...I may yet define more name tiles (for instance, the Greeks seem to like founding Sparta at a tile north of the alps I'd call Vienna if I had a choice), but for now I'd just like to play it for a bit...lol
 
and now, because I'm a masochist, I've decided I really don't like the smaller map...I'm redoing all the coords for the final release which will use the same map I used for RFC Irish...
 
Back
Top Bottom