Map Database  •  FAQ  •  RSS  •  Login

Problem with give house to different player.

<<

Adimax

Post 07 Aug 2014, 14:34

Problem with give house to different player.

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.
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 07 Aug 2014, 15:04

Re: Problem with give house to different player.

Tell us the error text
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 07 Aug 2014, 15:12

Re: Problem with give house to different player.

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;
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 07 Aug 2014, 15:23

Re: Problem with give house to different player.

@RandomLyrics: Perhaps you could add some explanations to that, to help the topicstarter to understand what you have done and to self-improve.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

Adimax

Post 07 Aug 2014, 17:09

Re: Problem with give house to different player.

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.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 07 Aug 2014, 17:26

Re: Problem with give house to different player.

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
<<

Jery

Laborer

Posts: 12

Joined: 26 Aug 2013, 18:51

KaM Skill Level: Skilled

Post 07 Aug 2014, 18:13

Re: Problem with give house to different player.

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
<<

Guest

Post 07 Aug 2014, 18:36

Re: Problem with give house to different player.

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.
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 07 Aug 2014, 18:50

Re: Problem with give house to different player.

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?
<<

Jery

Laborer

Posts: 12

Joined: 26 Aug 2013, 18:51

KaM Skill Level: Skilled

Post 07 Aug 2014, 18:52

Re: Problem with give house to different player.

Your procedure is not looped because you added the variable "changed"
<<

Jery

Laborer

Posts: 12

Joined: 26 Aug 2013, 18:51

KaM Skill Level: Skilled

Post 07 Aug 2014, 19:00

Re: Problem with give house to different player.

@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
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 07 Aug 2014, 19:24

Re: Problem with give house to different player.

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
<<

Adimax

Serf

Posts: 8

Joined: 07 Aug 2014, 18:57

KaM Skill Level: Average

Location: Poland

Post 07 Aug 2014, 19:42

Re: Problem with give house to different player.

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."
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 07 Aug 2014, 19:48

Re: Problem with give house to different player.

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]
<<

Jery

Laborer

Posts: 12

Joined: 26 Aug 2013, 18:51

KaM Skill Level: Skilled

Post 07 Aug 2014, 19:50

Re: Problem with give house to different player.

Try to turn off AI of second player. Tell a remake version where you test.

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 18 guests