Re: Problem with give house to different player.
PostPosted: 08 Aug 2014, 02:48
The problem was not in the script, it was a bug in the KaM Remake. I found the crash report you sent us and used it to fix the bug, so thanks!
The problem was that some units were killed while inside their house at the same time that the house was instantly destroyed and replaced. Then there was a bug which caused the units to be recorded as died twice, meaning the statistic for the total number of units went negative (which it is not allowed to do) and this caused a crash.
There is no problem with the original version of the script, it doesn't matter that it keeps happening every tick. "for i:=0 to -1 do" will just skip the loop, it will not loop backwards from 0 to -1 (you need to use "for i:=0 downto -1 do" to do that).
Your script will work fine in the next version of KaM Remake. For now you could make it work by destroying the houses/units on different ticks:
As you can see units will be destroyed on the tick after the houses, which should stop the crash from happening
But remember that your original script is ok, it's just there's a bug in the KaM Remake.
Using non-English names in scripts is a personal choice. It will make it harder for others to help you, but it's your script so it's your choice.

There is no problem with the original version of the script, it doesn't matter that it keeps happening every tick. "for i:=0 to -1 do" will just skip the loop, it will not loop backwards from 0 to -1 (you need to use "for i:=0 downto -1 do" to do that).
Your script will work fine in the next version of KaM Remake. For now you could make it work by destroying the houses/units on different ticks:
- Code:
if (States.StatArmyCount(1) = 0) then begin if (States.StatHouseCount(1) = 0) then begin ludzie:= States.PlayerGetAllUnits(1); for i:=0 to (length(ludzie)-1) do begin Actions.UnitKill(ludzie[i],true); end; end; budynki:= States.PlayerGetAllHouses(1); for i:=0 to (length(budynki)-1) do begin t:= States.HouseType(budynki[i]); x:= States.HousePositionX(budynki[i]); y:= States.HousePositionY(budynki[i]); Actions.HouseDestroy(budynki[i],true); Actions.GiveHouse(0, t, x, y); end; end;

Using non-English names in scripts is a personal choice. It will make it harder for others to help you, but it's your script so it's your choice.