Error in VEL - Events.lua

skodkim

Deity
Joined
Jan 16, 2004
Messages
2,497
Location
Denmark
Hi

When using VEM 123 I get a lot of errors concerning a variable wonUnit:

[673.471] Runtime Error: [string "C:\Users\hollenbo\Documents\My Games\Sid Me..."]:77: attempt to index global 'wonUnit' (a nil value)

I can't tell from the log where the error is, but a quick search through the files showed that VEL - Events.lua has the following in line 77:
if lostPlayer:IsBarbarian() and lostUnit:IsCombatUnit() and (wonUnit:GetDomainType() == lostUnit:GetDomainType()) then

Using other mods as well.

\Skodkim
 
Thank you for bringing this up! I'd forgotten to check a circumstance for Germany where a city (not a unit) wins combat against a barbarian. This should be fixed for v125. :thumbsup:
 
Thank you for bringing this up! I'd forgotten to check a circumstance for Germany where a city (not a unit) wins combat against a barbarian. This should be fixed for v125. :thumbsup:

Hi Thal

I'm currently in the middle of a game using VEM 123 so I'm hesitant to update. I did however change the one line in VEL - Events.lua that you changed in version 125 but I still get the following error message:

[1594.361] Runtime Error: [string "C:\Users\hollenbo\Documents\My Games\Sid Me..."]:77: attempt to index local 'wonUnit' (a nil value)

As said before I'm not sure if this is normal behavior. I haven't cleared cache or anything as I'm afraid I might ruin my current game.

\Skodkim
 
It was more complex than I first anticipated. I thought I'd got the changes in v125... if not, it should be in for v126. What was necessary was to redefine the barbarian-capture line to consider if the victorious object is a city:
PHP:
if lostPlayer:IsBarbarian() and lostUnit and lostUnit:IsCombatUnit() then
  if wonCity or (wonUnit:GetDomainType() == lostUnit:GetDomainType()) then
    local randChance = (1 + Map.Rand(99, "BL - General: barbCapture"))
    log:Info("Barbarian dead, checking " ..barbCapture.. " >= " ..randChance)
    ...

The problem was I originally just checked if wonUnit's domain was equal to lostUnit's domain. Cities don't have a domain so that failed when cities attack barbarians. I fixed this with the "wonCity or" statement, which means cities can capture either land or sea barbarians.
 
Back
Top Bottom