Unhandled exception when using Actions.HouseAddRepair
Hello, so lets get straight into the problem.
I came across this when I was scripting (how unsuspected), I kinda took over concept, but the important thing was that I tried to enhance it by repairing houses that do not need to be destroyed. But when we (me and friend) tested the map, we found out that when someone damages house in the earliest stage of building process, it crashes.
Lately I was thinking what could possibly cause this problem. And I fugured out that all problems are caused by script part down bellow (it's easy to fix in the script but despite the crash I think it should be considered as bug, please correct me if I am wrong). So what I suspect happend is this: in proc. OnHouseDamaged it gets taken damage and adds that damage to repair. It all uses ID of damaged building which is generated when building is placed, but in this case when building has no (0) health on start when you hit it, it'll destroy that building which will delete the ID but also the ID will be transfered to OnHouseDamage and will try to repair building which is not in the game anymore and also it will take all the damage from (defacto) non existing building.
So that's probably the case. And thanks for reading and hoopefully resolving.
I came across this when I was scripting (how unsuspected), I kinda took over concept, but the important thing was that I tried to enhance it by repairing houses that do not need to be destroyed. But when we (me and friend) tested the map, we found out that when someone damages house in the earliest stage of building process, it crashes.
Lately I was thinking what could possibly cause this problem. And I fugured out that all problems are caused by script part down bellow (it's easy to fix in the script but despite the crash I think it should be considered as bug, please correct me if I am wrong). So what I suspect happend is this: in proc. OnHouseDamaged it gets taken damage and adds that damage to repair. It all uses ID of damaged building which is generated when building is placed, but in this case when building has no (0) health on start when you hit it, it'll destroy that building which will delete the ID but also the ID will be transfered to OnHouseDamage and will try to repair building which is not in the game anymore and also it will take all the damage from (defacto) non existing building.
So that's probably the case. And thanks for reading and hoopefully resolving.
- Code:
begin TypeOfHouse := States.HouseType(aHouseId); Owner := States.HouseOwner(aHouseId); TakenDamage := States.HouseDamage(aHouseId); if (TypeOfHouse <> 29) and (TypeOfHouse <> 17) and (TypeOfHouse <> 21) and (Players[Owner].Enslaved = false) then begin Actions.HouseAddRepair(aHouseId, TakenDamage); end else if (TypeOfHouse = 29) and (TakenDamage > 250) and (Players[Owner].Enslaved = false) then begin Actions.PlayerShareFog(Owner, aAtacker, true); Actions.PlayerAllianceChange(Owner, aAtacker, true, true); end; end;
Last edited by tomasara413 on 28 Jun 2016, 07:17, edited 1 time in total.