Python (civ4 scripting language) tutorial thread

unit = player.firstUnit()
plot = unit.getReconPlot()
self.recon[unit.getID()] = (unit,plot.getX(),plot.getY())

1.What store in "unit"?
2.unit.getID() is no variable "unit"?
3.How i can get: Player(2) have or not unit with ID=5846287?:confused:

Were thanks for comments!:)
 
Unit ID is just an ID for every unit.
It's variable and depends from game to game.
Let's say, you start with settler and warrior. The settler has maybe the ID 1, the warrior maybe 2 (or vice versa).
If you build now an archer, it will get the ID 3. And so on, for every unit.
 
If in the game are 6 players with IDs=0,1,2,3,4,5. If 2 players are died with IDs=2,4, other players have IDs=0,1,_,3,_,5 or IDs=0,1,2,3? PlayerID is exceptional number in Civ game and code or it's variable?
 
The IDs are not hardcoded, they are variable.
Yes, IDs are not hardcoded. Are they not variable in the time of whole game?
*************************
Is it be passeble: gc.Player(2).getUnit(25) == gc.Player(5).getUnit(25) ?
 
Yes, IDs are not hardcoded. Are they not variable in the time of whole game?

Uh, sorry: They will not change during the game.

But there is nothing which says, CIVILZATION_AMERICA has to have the ID 1, or so.

Is it be passeble: gc.Player(2).getUnit(25) == gc.Player(5).getUnit(25) ?

:think: what do you want to do?

This will probably not work, because you check, if the units are the same.
You could check, if the unit type or the unit class are the same, but not this.
 
Is this the thread for basic everyday modding questions? If so...

I modified the Spy's commerce output from 1/3 to 0/3 - when I load an old game (pre-mod) I see some oddness in a few cities: they show +1 espionage for Specialist (upper left espionage details) even though there is no Specialist. Is this to be expected? Will such changes only work properly with new games?
 
Please add a screenshot, because i have no idea, what you mean.

Using the BUG mod (if that matters). Say I change the spy specialist to be 0 science 3 espionage instead of 1 science 4 espionage (in the xml file). I then load an old game in which a city had 2 spy specialists assigned. I hover my mouse over the espionage points in the top left of the city window. In that window it shows that I still am getting 8 espionage from Specialists (I'd expected 6). If I unassign the two Spy specialists, it then shows that I have 2 espionage from Specialists - even though there are no Spy specialists assigned. I assume that everything would work fine if I started a new game with the change in place. I'm just wondering why the change doesn't affect previously saved games.
 
Just a matter, how it's designed and programmed.
In this case, just the spy points from the 2 specialists are substracted. They are 6 together, so 8-6 is 2, correct.
Another way would be to re-calculate all the spy points for the city, but this just has not been done.
 
In general, can you make a modification to an xml file and test it with a previously saved game. For example, I have a game saved before steel. Can I make mods to objects that occur after steel and expect the save game to work properly?
 
If you add or remove an entry from an XML file, it will break the game.
If you only change some values (like the strength of a unit), then it also should work for older things in the savegame.
But don't move whole entries in the XML files (like just placing the units in another order). That would lead to crazy results.
 
Okay i learned the Python, but is there a lesson on how to use python on Civ4? I just need a basic understanding.
 
Do you have problems with anything special, or do you have a concrete problem at the moment?

All the needed commands, which are special for civ, can be found here.
And it might be easier for you, to start with looking at some of the smaller works from other people.
 
Hi everyone. =D
First of all: Gingerbread Man, thank you very much for your great tutorial.
It's helping me a lot.


Then...
I have a problem.
I'd like to create a new method (or function? I'm still learning and I still don't know exactly how is technically defined what I'm aiming for) for getting commerce types bonus (culture, research, money) from a specific terrain type.

simple example:
changing Moai Statue wonder from adding +1 production to all seaplots in the city to adding +X culture to all seaplots in the city.

Moai Statue (as Lighthouse and many other buildings) does that with the SeaPlotsYieldsChanges method (or at least, I think so; correct me if I'm wrong.)
But this method enable to change only Yields types (food; production; raw commerce).
So I was thinking to create a new whole method, similar SeaPlotsYieldsChange (cloning its structure), but dealing with commerce types.

The big problem is that I can't find the SeaPlotsYieldsChanges script.
Is there someone that can give me the exact location?



...but recently I'm thinking that maybe it would be too hard to make such a method.
It would be easier to make another one:
one similar to the ImprovementFreeSpecialist used by National Park national wonder, but adding commerce types and per terrain type plot instead.
Is there someone who can give me some hints about this, please?
 
First: welcome at CFC.

Second: Man, you've directly chosen something, which has problems at more than one place.
a) The output-generation of plots is not controlled by python files, it's controlled by the CvGameCoreDll, which is generated out of the SDK files, which are written in C++.
b) Plots at all do not generate any commerce. If you want to let them do this, you'll have to make a major hack into the system.
 
Back
Top Bottom