BUG & Problems with adding new Diplomacy Options

These are the names of the two parameters this function expects. Unlike C++ you don't ever declare the type of a variable. Every variable can hold any type of value or object. You can assign an int to a variable currently holding a string. Variables are truly just names for values and objects.

No datatypes? None?

PlayerUtil.getPlayer(player)​
PlayerUtil is a Python module (PlayerUtil.py) that has a function called getPlayer() that takes a single "player" parameter.

BUG's PlayerUtil module makes dealing with players and teams easier with functions like getPlayer(), getPlayerAndID(), getActivePlayerID(), etc. All of the functions in it that take a player will accept either a CyPlayer object or its PlayerTypes ID. This makes it so I don't have to worry about which thing I have. Here I need a CyPlayer which is exactly what PlayerUtil.getPlayer() returns. If you pass it a CyPlayer, it returns it. If you pass it a PlayerTypes, it uses gc.getPlayer(ePlayer) to look it up.

Okay, so your just using this to grab which player it is.

getCity(trade.iData)​
This uses the CyPlayer.getCity() function to get the CyCity with the ID stored in the TradeData's iData field. When you use -> in C++ to access a function or value on a pointer, you are doing something similar. C++ also has the . operator for when you have an actual object instead of a pointer to an object.

Okay. But let's say I need to get a unit, would I write getUnit(trade.iData), or would I need to go look at CyUnit to see what functions are there?
return ...getName()
 
Python has built-in data types and objects, but you never declare them when using variables. In C++ to assign 5 to a variable named x you need to first declare that x is an int:

int x = 5;​

In Python, you let the interpreter figure it out:

x = 5​

CyPlayer has a getUnit() function you can use to get the CyUnit. Check out the online BTS Python API.
 
Python has built-in data types and objects, but you never declare them when using variables. In C++ to assign 5 to a variable named x you need to first declare that x is an int:
int x = 5;​
In Python, you let the interpreter figure it out:
x = 5​
CyPlayer has a getUnit() function you can use to get the CyUnit. Check out the online BTS Python API.

Thanks for the link to the API, that's pretty handy. I'll look up some of those.
 
Back
Top Bottom