Page 1 of 1
Austria dead event crash
Posted: Sun Jan 24, 2021 1:10 am
by Kossatx
Hi people, any idea about why the game crashes?
The crash:
Code: Select all
[02:05:40][10472]game/game_events.lua:16782(global AustriaDead) game/game_events.lua:16782: attempt to perform arithmetic on field 'artillery' (a nil value)
The function:
Code: Select all
function AustriaDead()
local austria = game:GetFactionById(3)
local italy = game:GetFactionById(8)
local russia = game:GetFactionById(4)
if GetEvent("AustriaDead") == 0 then
local dead = austria.luaData.statsCasualties["ground"] + austria.luaData.statsCasualties["naval"] + austria.luaData.statsCasualties["air"] + austria.luaData.statsCasualties["artillery"] + austria.luaData.statsCasualties["armour"]
if dead > 8000
and austria.alliance.id == 2 then
SetEvent("AustriaDead", game.turn)
if austria.morale > 100 then
local value = austria.morale - 100
austria.morale = austria.morale - value
end
austria.luaData.collaps = austria.luaData.collaps +3
ui.resourcesPanel:Refresh()
end
end
end
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 11:07 am
by Robotron
For some reason the casualties stat for artillery has become nil. I've seen that happen before in MP but was unable to find the cause because MP games are difficult to fix.
But this is from a singleplayer game, right? If so, then I might be able to find a solution.
Do you still have the last AutoSaveEndTurn before the crash happened?
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 1:07 pm
by Kossatx
Here it is. It is a single player game, as you know I play an own variant of your POTZBLITZ MOD, so I don't know if it would be a problem to fix it. Thanks again Robotron, have a nice 2021 year!
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 2:33 pm
by Robotron
Looks like the bug was caused by a Russian land unit attacking an Austrian artillery, crippling the value for some reason.
I've not yet found out why exactly this happened.
At least I could fix your savegame so you can continue but until I found the cause of the bug the issue might happen again.
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 2:50 pm
by Kossatx
It now runs perfectly

Thanks again! Which program do you use to edit savegame files?
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 3:25 pm
by Robotron
I did not actually edit the savegame file itself which is impossible because of encryption.
I loaded your savegame and then changed the damaged value from "nil" to 0 while the game was running and then saved the game.
Re: Austria dead event crash
Posted: Sun Jan 24, 2021 5:37 pm
by Kossatx
Robotron wrote: ↑Sun Jan 24, 2021 3:25 pm
I did not actually edit the savegame file itself which is impossible because of encryption.
I loaded your savegame and then changed the damaged value from "nil" to 0 while the game was running and then saved the game.
In which file have you changed the "nil" value to "0"? It couldn't be any savegame file because they are encripted

Re: Austria dead event crash
Posted: Sun Jan 24, 2021 6:45 pm
by Robotron
You can't find the definitions for these variables about kills and casualties in any specific file, because these variables, among many others, are stored in the game's internal table of variables which is created at the start of a game by a rather difficult to explain procedure.
However you can directly access these variables from any function.
Because I would need to fix the problem before the "end turn" button was pressed (pressing "end turn" would crash the game, right?) I chose the following function:
which is in the file called
main_hud.lua
which is in the following folder
Data/Scripts/ui
function ui.SelectHex(hex) is a function that deals with all things that can happen when you click on a hex.
I knew from the logfile that the problem was in austria.luaData.statsCasualties["artillery"] but another test showed that Russia was also affected.
So I inserted the following for-next loop into that function so it would be executed the next time when I clicked on any hex. Then I loaded your corrupted savegame.
Code: Select all
for faction in game.factions do
if faction.luaData.statsCasualties["artillery"] == nil then
faction.luaData.statsCasualties["artillery"] = 0
end
end
This replaced
ALL nil values with 0, which is of course not the true value that the variable had (before it got set to nil by the bug which I still have to find) but it would allow to at least continue the game. I tested this by clicking on the "management" panel which shows the kills/casualties and it worked again (it crashed before because of the nil values - you can't show nil values because they are...well, nil).
Finally I simply saved the game with the "repaired" variables.
Does that make any sense to you?

Re: Austria dead event crash
Posted: Sun Jan 24, 2021 8:21 pm
by Kossatx
Wow! Very good explanation
