It is really a bad idea to use your own language names when coding. Not everybody here understands Polish, and knowing the names actually helps in getting what the script is supposed to do. Also, I can't see the error image. Can you write it down or use another image hosting?
Your code seems to do something like that:
For all the buildings of player 2:
-remember building's type and position
-destroy the building
-make a new one, belonging to player 0 in the same spot
There is a problem though. You are completely ignoring time. The code will run LOTS of times (in fact, it will run all the time). As RandomLyrics suggests, you should use a new if loop, which takes time into account:
- Code:
procedure OnTick;
var buildings, people: array of integer;
var t,x,y,i: integer;
begin
if States.GameTime mod 10 = 0 then
begin
//here paste the entire code you had inside OnTick
end;
end;
This way, the code will run each 10 ticks (=1 second) instead of running all the time. Don't ignore it, even if the reason it gives an error is different (see below), you should care about time too, because if you keep ignoring it some strange things may happen, not to mention that you waste your processor's time.
@Jery: what if he destroyed all buildings of player 1 and remade them as player 0's buildings, and the game tries to find more but fails? How will the game treat "for i := 0 to -1"? Will it go backwards, trying to use both 0 and -1? That would explain why it tries to find non-existent cell of an array - budynki[-1].
Anyway. Having said above, I need to ask: how many times you want this code to run? I think you wanted to "give" the buildings from an AI player to human player only once. Maybe another if statement will help. When do you want the buildings to change their owner?