Page 13 of 26
Re: Dynamic Script Usage
PostPosted: 17 Jun 2013, 14:51
by Islar
I had some difficulties with scripting with OnHouseDestroyed but i figured it out and it worked. Now i have RC4 but now it don't work anymore. I get an error with ONHOUSEDESTROYED(507:1): type mismatch. The same i had before. There nothing changed in my script file so i don't no what is wrong.
Could someone help my or give my some suggestions what i can do?
Re: Dynamic Script Usage
PostPosted: 17 Jun 2013, 15:18
by Lewin
OnHouseDestroyed has changed a bit in this release. It was merged with OnHouseLost (to make things simpler), so it now needs another parameter:
aDestroyerIndex: Integer; //Index of player who destroyed it
Here's the description from our Wiki for OnHouseDestroyed:
Occurs when a house is destroyed. If DestroyerIndex is -1 the house was destroyed some other way, such as from Actions.HouseDestroy. If DestroyerIndex is the same as the house owner (States.HouseOwner), the house was demolished by the player who owns it. Otherwise it was destroyed by an enemy. Called just before the house is destroyed so HouseID is usable only during this event
Read more here:
http://code.google.com/p/castlesand/wik ... ptsDynamic
Re: Dynamic Script Usage
PostPosted: 18 Jun 2013, 08:43
by Islar
Hi
In my mission the AI must attack two towers. One group must attack a tower at the same time another group must attack another tower. Both groups must have 8 militia when they go attack. when they destroyed those two towers they must go back to their defence positions.
The only problem is that i don't know how i can make this. Could someone help my to give my an example?
Edit: never mind, i figured it out and it works how i want it.

Re: Dynamic Script Usage
PostPosted: 18 Jun 2013, 14:20
by Tef
I'm getting a new peculiar crash in the 4th RC. First I wish to mention that the scriptvalidator / Kam Remake do not detect onUnitKilled as wrong (now onUnitDied). After I fixed that, I am getting strange crashes. I have isolated the crash so far, that I have figured out that it happens when I give a unit or soldier and then instantly kill it again. The part of the script that causes the script is added below. Note that this script worked just fine in RC3!
*EDIT: the game does not actually crash, it just 'hangs' as if it gets into some eternal loop
*EDIT2: setting a '//' in front of the line with 'Actions.UnitKill(EmptyUnit,false);' will resolve the crash. However, I do really need the units to die! :p
*EDIT3: I have noticed that the freshly created and instantly dying units tend to be recreated over and over again?
- Code:
if KillQueue[QueueWalker].RecordDesiredAction = 'KillEmptyUnit' then begin
ThatUnitType := KillQueue[QueueWalker].RecordStuff; // has unittype stored
ThatUnitX := KillQueue[QueueWalker].RecordUnitX;
ThatUnitY :=KillQueue[QueueWalker].RecordUnitY;
if ThatUnitType < 14 then begin
EmptyUnit := Actions.GiveUnit(PLAYER_1,ThatUnitType,ThatUnitX,ThatUnitY,States.KamRandomI(8));
end;
if ThatUnitType >= 14 then begin
EmptyGroup := Actions.GiveGroup(PLAYER_1,ThatUnitType,ThatUnitX,ThatUnitY,States.KamRandomI(8),1,1);
EmptyUnit := States.GroupMember(EmptyGroup,0);
end;
Actions.UnitKill(EmptyUnit,false);
end;
[/size]
Never mind, fixed it.
Re: Dynamic Script Usage
PostPosted: 18 Jun 2013, 15:01
by Lewin
It won't report an error with OnUnitKilled because it now looks like any other procedure you might write and use within your script.
Hanging could mean you have some kind of infinite loop, such as adding and killing a unit during OnUnitDied (which causes OnUnitDied to occur and do the same thing over and over again...) How did you fix it in the end? Maybe other people here will benefit from your answer?
Re: Dynamic Script Usage
PostPosted: 18 Jun 2013, 15:07
by Tef
How did you fix it in the end? Maybe other people here will benefit from your answer?
This was part of my earlier mentioned exploding vagabonds. A killed vagabond (onUnitKilled) would generate a circle of instantly dying units around it. However, with onUnitDied, all dying units (even though they have no killerID) in this circle would ALSO trigger this procedure, which generates dying units in a circle, which triggers the procedure, etc etc etc. So just by checking if OnUnitDied has a KillerID other than -1 fixed it. Actually very simple and logical...
Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 02:52
by Lewin
How did you fix it in the end? Maybe other people here will benefit from your answer?
This was part of my earlier mentioned exploding vagabonds. A killed vagabond (onUnitKilled) would generate a circle of instantly dying units around it. However, with onUnitDied, all dying units (even though they have no killerID) in this circle would ALSO trigger this procedure, which generates dying units in a circle, which triggers the procedure, etc etc etc. So just by checking if OnUnitDied has a KillerID other than -1 fixed it. Actually very simple and logical...
Ah right, so it got into a loop where each time OnUnitDied was executed, it killed another 9 units causing OnUnitDied to be executed 9 more times, and thus froze the game... Glad you solved the problem

Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 15:18
by Tef
Could the length for dynamic scripts be increased? Because KAM Remake gives me the error 'ERangeError: Range check error' as soon as the 'length' of the .script file gets longer than 65533. I have verified this, because just removing/adding a comment can make the mission crash upon startup, which makes no sense to me.
Yes I know that a length of > 65533 is ridiculously long, but I am making serious work of the scripted map competition and I have dozens of custom procedures doing pretty advanced stuff, so I need the .script file to be longer. Please?...

Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 15:37
by Lewin
Could the length for dynamic scripts be increased? Because KAM Remake gives me the error 'ERangeError: Range check error' as soon as the 'length' of the .script file gets longer than 65533. I have verified this, because just removing/adding a comment can make the mission crash upon startup, which makes no sense to me.
Yes I know that a length of > 65533 is ridiculously long, but I am making serious work of the scripted map competition and I have dozens of custom procedures doing pretty advanced stuff, so I need the .script file to be longer. Please?...

65k is quite a long script, good work

It's quite likely that there is some limiting factor causing problems with long scripts which is unintentional. However, I made a script with 10MB of comment lines and then a simple OnMissionStart, and it worked fine, so the limit might be more complicated than simply file size (e.g. number of lines, number of statements). Would you be able to send us a script file which causes it to crash on startup so we can test it? Hopefully we'll be able to remove this limitation

Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 17:34
by Islar
Hi
could some tell my how to use a ''array''? Because i want to use Actions.PlayerWin and they ask an array of player index. It would also be fine to give my an example to use this.

Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 17:41
by Shadaoe
Here is an example with actions.PlayerWin
Actions.PlayerWin([2], False); //Makes the player 3 (since the player number starts with 0 in the scripts) win. The "false" means that his allies don't win with him.
Actions.PlayerWin([2, 3], True); //Makes the players 3 and 4 win, and their allies along with them
Re: Dynamic Script Usage
PostPosted: 19 Jun 2013, 21:23
by Tef
Would you be able to send us a script file which causes it to crash on startup so we can test it? Hopefully we'll be able to remove this limitation

Lewin, I sent you a PM!
Re: Dynamic Script Usage
PostPosted: 20 Jun 2013, 13:39
by Tef
Since I discovered the following bug (is it?) through scripting, I'm still going to put it in this topic. I've discovered the following: I have a script that should kill the inhabitant of a house when the house gets destroyed (by the enemy). So I tried to do: UnitKill(UnitAt(HouseX, HouseY)) within OnHouseDestroyed. I know this is where it's inhabitant is suppose to be, because that's what you find out after using Actions.PlayerGetAllUnits and search for the unit within that array. However, the unit doesn't get killed! I have used a workaround to resolve this: within OnHouseDestroyed, search for a unit that has the same x position and y position as the destroyed house, and then kill it directly through UnitKill(UnitID).
I'm not sure if you could call this a bug, but I just wanted to report this typical thing.
Re: Dynamic Script Usage
PostPosted: 20 Jun 2013, 13:44
by Lewin
That's not a bug, you cannot use UnitAt to access units within a house. For a start there could be 100 serfs stuck within one storehouse, so which one does it choose?
Re: Dynamic Script Usage
PostPosted: 20 Jun 2013, 13:52
by Tef
Never thought about buildings with multiple units in it.
*slaps himself in the face for spamming this topic with ignorant posts*