Page 1 of 2

Problem with give house to different player.

PostPosted: 07 Aug 2014, 14:34
by Adimax
The problem stems from the script
  Code:
procedure OnTick; var budynki, ludzie: array of integer; t,x,y,i: integer; begin if (States.StatArmyCount(1) = 0) then begin ludzie:= States.PlayerGetAllUnits(1); for i:=0 to (length(ludzie)-1) do begin Actions.UnitKill(ludzie[i],true); 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; end;
The script works, but after some time error pops up.
I sent an error report. I would be grateful if someone helped me with this.
Bug only occurs enter the code Actions.GiveHouse.

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 15:04
by Krom
Tell us the error text

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 15:12
by RandomLyrics
Copy that :>
  Code:
VAR CHANGED: boolean; procedure OnTick; var budynki, ludzie: array of integer; t,x,y,i: integer; begin if (States.StatArmyCount(1) = 0) and ( CHANGED = false ) then begin ludzie:= States.PlayerGetAllUnits(1); for i:=0 to (length(ludzie)-1) do begin Actions.UnitKill(ludzie[i],true); 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; CHANGED:= true; end; end;

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 15:23
by Krom
@RandomLyrics: Perhaps you could add some explanations to that, to help the topicstarter to understand what you have done and to self-improve.

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 17:09
by Adimax
Here are the contents of the error:

Image


I checked your idea of ​​changing the code to:
  Code:
procedure OnTick; var budynki, ludzie: array of integer; t,x,y,i: integer; changed: boolean; begin if ((States.StatArmyCount(1) = 0) and (changed = false)) then begin ludzie:= States.PlayerGetAllUnits(1); for i:=0 to (length(ludzie)-1) do begin Actions.UnitKill(ludzie[i],true); 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; changed:= true; end; end;
The above code did not change, the error still is.

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 17:26
by RandomLyrics
Adimax u did it wrong ;p your script is running all the time, for every tick script gets allunits and allhouses and removes them, i think when he ddint have anything to remove game crashes. I give u soultion that make your script run olny once.
When armycount = 0 then run script once.
You have to keep CHANGED out from OnTick, CHANGED should be Global Var.

PL: twoj skrypt caly czas sie powtarza, zauwazysz ze masz tam gdy armycount = 0 to robi cos. Ale gdy usuniesz wszystkie jednostki to dalej ma 0, wiec caly czas powtarza :) musisz umiescic CHANGED w globalnych zmiennych, skopiuj po prostu to co Ci wstawilem i zastap stary skrypt tym. Ogolnie teraz leci tak: jesli armycount = o i 'zmienione' = false to leci robi skrypt, na koncu ustawia ze "zmienione"= true, czyli budynki zostaly juz zmienione i nie trzeba tego potwarzac. Mam nadzieje ze rozuemisz :) Umiesciles CHANGED w procedurze OnTick, czyli za kazdym razem jest tworzeona nowa taka zmienna i za kazdym razem ma wartosc FALSE wiec zawsze bedzie sie powtarzac i nic nie da ze na koncu zmienisz na true :P dlatego to musi byc w globalnych zmiennych, ktore wywolana sa po odpaleniu mapy

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 18:13
by Jery
Why do you believe that the error is in this part of the code? I do not see the error in this script. This error occurs when you use a non-existent cell of array.

PS. I want to encourage you to write so
  Code:
for I := Low(budynki) to Hight(budynki) do

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 18:36
by Guest
New code:
  Code:
var changed: boolean; procedure OnMissionStart(); begin changed := false; end; procedure OnTick; var budynki, ludzie: array of integer; t,x,y,i: integer; begin if ((States.StatArmyCount(1) = 0) and (changed = false)) then begin ludzie:= States.PlayerGetAllUnits(1); for i:=0 to (length(ludzie)-1) do begin Actions.UnitKill(ludzie[i],true); 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; changed:= true; Actions.ShowMsg(0, 'Wykonane'); end; end;
Error still persists, despite the change in the code. I wrote a message to see if this procedure is looped. Result - I received only one message. I am doing something wrong, or this is not the cause of my problem.

PL: Dziekuje za informacje. Doczytałem, że procedura OnTick wykonuje się 10 razy na sekunde, co rzeczywiscie moglo powodowac problem, jednak powyzszy kod pokazuje, ze podana procedura wykonuje sie tylko raz, chyba, ze nadal cos zle robie by naprawic ten problem.

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 18:50
by sado1
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?

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 18:52
by Jery
Your procedure is not looped because you added the variable "changed"

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 19:00
by Jery
@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?
this situation it is necessary to simulate or view source code
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].
0 iterations will be executed in this case

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 19:24
by RandomLyrics
Adimax, so as u can see the error is not result of this script :)
Make printscreen of this error and put it here. Also copy here all of your script if theres something more :)
PL: wrzuc screena errora i caly kod jaki masz :) mozesz go na http://pastebin.com/ wjebac ;D
Check this out: http://pastebin.com/2i5bNY17

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 19:42
by Adimax
Hi,

It is not a problem with the script time and variables. When i delete buldings only then sctipt works perfect. Problem is when i create new buildings for second player in the same place. The problem is not in my script, because it is start one time only, and error i have is show every few seconds...


about error form screen :

"Exception occured: ERangeError: Range check error."

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 19:48
by RandomLyrics
Send me the map, or upload it here via zippyshare.com
Range check error coz u want value from non existing index of array. like table is 0..2 and u want info from [4]

Re: Problem with give house to different player.

PostPosted: 07 Aug 2014, 19:50
by Jery
Try to turn off AI of second player. Tell a remake version where you test.