isAIPlayable, python

Lplate

Esus (Allegedly)
Joined
Feb 8, 2011
Messages
578
Location
Ireland
Hi,

I want to check if civs are playable by the AI using python. I think the isAIPlayable should return 1 or 0 depending on the civ's xml entry but I don't know what to apply this to.

Any advice?

-----
Edit - sorted
Spoiler :
Code:
        if not gc.getCivilizationInfo(pPlayer.getCivilizationType()) == None:
                bAIActive = gc.getCivilizationInfo(pPlayer.getCivilizationType()).isAIPlayable()
                if bAIActive == 1:
 
Not sure what exactly do you want, but whatever it is you should keep it simple:

Code:
if iPlayerIndex [I][B](or whatever)[/B][/I] > -1:
   if gc.getCivilizationInfo(gc.getPlayer(iPlayerIndex).getCivilizationType()).isAIPlayable():
     [I][B]if true then do this[/B][/I]
 
Code:
if bAIActive == 1:
Checking if a bool is 1 could be dangerous. You should test the true/false value of it, which would be:
Code:
if bAIActive:
The thing is, if for some reason bAIActive is 2, then the true/false value is still true, but your test will make it false. Checking if it is != 0 should also work.

Never assume anything regarding the int value of a bool as you can generally only be 100% sure that false is 0 and true is != 0. While 1 is often used, I have encountered other values used for true. It's 2 in ruby scripting and 0xFFFFFFFF internally in 32 bit PPC cpus, which in turn is how they behave in C, even if the very same code would use 1 as true on x86 :crazyeye:

For the same reason, never assume boolA == boolB is safe. You could get 1 == 2 even though both are true. !boolA == !boolB should provide the correct answer as they are inverted according to the same standard.

I don't really get what the problem in this thread is though. What I wrote here is about general bool coding issues.
 
Thanks for the tips
 
Back
Top Bottom