Austria dead event crash

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Post Reply
Kossatx
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Austria dead event crash

Post 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    
Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2173
Joined: Tue Nov 23, 2010 3:35 pm

Re: Austria dead event crash

Post 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?
Image
Slitherine's Commander the Great War - Director's Cut: POTZBLITZ mod!
FIND IT HERE: http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610
Kossatx
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Re: Austria dead event crash

Post 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!
Attachments
AutoSaveEndTurn.rar
(134.18 KiB) Downloaded 67 times
Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2173
Joined: Tue Nov 23, 2010 3:35 pm

Re: Austria dead event crash

Post 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.
Attachments
arty bug savegame fixed.zip
(135.89 KiB) Downloaded 88 times
Image
Slitherine's Commander the Great War - Director's Cut: POTZBLITZ mod!
FIND IT HERE: http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610
Kossatx
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Re: Austria dead event crash

Post by Kossatx »

It now runs perfectly :D Thanks again! Which program do you use to edit savegame files?
Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2173
Joined: Tue Nov 23, 2010 3:35 pm

Re: Austria dead event crash

Post 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.
Image
Slitherine's Commander the Great War - Director's Cut: POTZBLITZ mod!
FIND IT HERE: http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610
Kossatx
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Re: Austria dead event crash

Post 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 :idea:
Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2173
Joined: Tue Nov 23, 2010 3:35 pm

Re: Austria dead event crash

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

Code: Select all

function ui.SelectHex(hex)
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? :)
Image
Slitherine's Commander the Great War - Director's Cut: POTZBLITZ mod!
FIND IT HERE: http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610
Kossatx
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Re: Austria dead event crash

Post by Kossatx »

Wow! Very good explanation :!:
Post Reply

Return to “Commander the Great War : Mods & Scenario Design”