Vehem
Modmod Monkey
- Joined
- Nov 22, 2005
- Messages
- 3,219
so for example --
if PyPlayer(gc.getPlayer(1)).getUnitList() == 0:
[do action stuff]
[other action stuff]
Would this check to see if the list for player 1 (actually the second player since the first player is "0") is empty and then execute the actions?
Am I parsing the conditional statement correctly, or does the "==" need to be an "=" or something else? Do you still use "0" for an empty set or is there another symbol?
I've noticed that Age of Ice uses some getUnitClassCount statements that have "> 0" as the condition. (These are in the onCombatResult code and check to see if Mulcarn or Kylorin were killed). I would have figured it should be written "=> 0" for python, but I think that there is a nuance to coding that I am missing here. Is it different for strings versus integers?
You'd need to check that the length is equal to 0 rather than the "list is equal to 0";
Code:
if len(PyPlayer(gc.getPlayer(iPlayerNum)).getUnitList()) == 0:
The "==" operator is read as "is equal to", whilst the "=" is read as either "is" or "becomes" (depending on your background ":=" is also "becomes").
- If you're comparing two things, you need to see if they "are equal to" each other with "==".
- If you're changing the value of a variable, you can say that it "is" the new value, or "becomes" the new value with "=".
"==" is comparison
"=" is assignation
The "GetUnitClassCount" tests are to see if any of that UnitClass exist. If there are greater than 0, then at least one of that unitclass exists. If there is 0, then none of that unitclass exists.
The example you gave of ">= 0" (the equals is always on the right in comparison operators btw >= <= == !=) wouldn't be of much use as it's checking if there's 0 or more units of that type. There are no occasions where counting the units should give a negative value - you'd never have "-5 goblins"