Any idea to fix this crash?

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

Moderators: Slitherine Core, The Lordz

Post Reply
Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Any idea to fix this crash?

Post by Kossatx » Fri May 17, 2019 11:10 pm

Hi, this is the error log message:

Code: Select all

[00:51:56][8596]game/game_events.lua:6393(global RussiaSupplyCrisis) game/game_events.lua:6393: attempt to index field 'originalFaction' (a nil value)
This is the function section with 6393 line:

Code: Select all

		----- CONQUER BONUS ---------
		for hex in russia.hexes do
			if hex.originalFaction.id == 2 or hex.originalFaction.id == 3 then
				russia.luaData.crisis = russia.luaData.crisis +5
				--LogUi("ADDED!")
			end --6393 line
		end	
And this is the full function:

Code: Select all

function RussiaSupplyCrisis()
    local russia = game:GetFactionById(4)
	local germany = game:GetFactionById(2)
	local turkey = game:GetFactionById(5)
	local austria = game:GetFactionById(3)
	local impassable = game:GetFactionById(24)


		 local warsaw = game:GetHex(112, 23)
		 local krakow = game:GetHex(110, 27)
		 local danzig = game:GetHex(110, 19)
		 local koenigs = game:GetHex(112, 17)
		 local lodz = game:GetHex(110, 24)
		 local radom = game:GetHex(112, 25)
		 local lemberg = game:GetHex(115, 28)
		 local tarnopol = game:GetHex(118, 28)

		 
		 
		 local chance = math.random(1,100)
		 local bonus = 0
		 local duration = 5
		 
		 if (player.alliance.id == 1 and game.type == Game.TYPE_SINGLE)  then
				duration = math.random(6,7) 
		end
		 
		 if warsaw.alliance.id == 2 then
			duration = duration + 1
		 end
		
		if GetEvent("RussiaSurprise") >0 then
			duration = duration + 1
		end


if  GetEvent("RussiaSupplyCrisis") == 0  
	and russia.alliance.id == 1  
	and game.date.year >= 1915
	and impassable.luaData.winter == 0
	and russia.luaData.crisis <= 0 then
	
			if (player.alliance.id == 2 
				and game.type == Game.TYPE_SINGLE 
				and warsaw.alliance.id == 2) 
					or russia.luaData.crisis <= 500 
					or GetEvent("Rasputin") >0 
					or GetEvent("Gorlice") >0
					or (player.alliance.id == 1 and game.type == Game.TYPE_SINGLE) 
					or  game.type == Game.TYPE_PBEM then

					SetEvent("RussiaSupplyCrisis", game.turn)
				
					if russia.morale >= 100 then
						ChangeFactionMorale(russia, - 25)
					end
					russia.luaData.steamroller = -1
					russia.luaData.collaps = russia.luaData.collaps +1
			end
end


if GetEvent("RussiaSupplyCrisis") == 0 
	and russia.alliance.id == 1 then
	
		--- FACTORY BONUS ----
		if russia.luaData.factories >0 then
				russia.luaData.crisis =  russia.luaData.crisis + (russia.luaData.factories * 5)
		end	

		 ---- ALL EAST BONUS ----"DEFEND MOTHER RUSSIA"
		 if GetEvent("AllEast") <= 0 then
			russia.luaData.crisis =  russia.luaData.crisis - math.random(1, game.turn)
		 else
			russia.luaData.crisis =  russia.luaData.crisis + math.random(game.turn /2, game.turn)
		 end
		
		--- CITY BONUS -----
		if lodz.alliance.id == 1 then
		 russia.luaData.crisis = russia.luaData.crisis + math.random(1,6) + math.random(1,6) + math.random(1,6)
		end
		if radom.alliance.id == 1 then
		 russia.luaData.crisis = russia.luaData.crisis + math.random(1,6) + math.random(1,6) + math.random(1,6)
		end
		
		if warsaw.alliance.id == 1 then
			russia.luaData.crisis = russia.luaData.crisis + math.random(1,6)  + math.random(1,6) + math.random(1,6) + math.random(1,6) + math.random(1,6) + math.random(1,6) 
		 elseif warsaw.alliance.id == 2 or GetEvent("WarsawCaptured") >0 then
			russia.luaData.crisis = russia.luaData.crisis - (math.random(1,6) +   math.random(1,6) + math.random(1,6) + math.random(1,6) + math.random(1,6) + math.random(1,6))
		 end
		 
		 if krakow.alliance.id == 1 then
			russia.luaData.crisis = russia.luaData.crisis  +  math.random(1,6) +  math.random(1,6)
		 end

		 if danzig.alliance.id == 1 then
					russia.luaData.crisis = russia.luaData.crisis +  math.random(1,6) +  math.random(1,6)
		 end
		 
		 if koenigs.alliance.id == 1 then
					russia.luaData.crisis = russia.luaData.crisis +  math.random(1,6) +  math.random(1,6)
		 end
		 if lemberg.alliance.id == 1 then
					russia.luaData.crisis = russia.luaData.crisis +  math.random(1,6) +  math.random(1,6)
		 end
		
 
		---- ARMY SIZE DRAIN ----
		for unit in russia.units do															    
			if unit.alive 
				and unit.hex ~= nil 
				and unit.prototype.name ~= "smallgarrison" then
				if unit.hex.originalFaction ~= nil 	
					and unit.hex.terrain.type == Terrain.LAND then
						if game.date.year == 1914 then
					--	russia.luaData.crisis = russia.luaData.crisis -1
						else
							---player.alliance.id == 2 and game.type == Game.TYPE_SINGLE
							russia.luaData.crisis = russia.luaData.crisis - (game.date.year - 1914)
						end
						
				end
			end
		end
		----- CONQUER BONUS ---------
		for hex in russia.hexes do
			if hex.originalFaction.id == 2 or hex.originalFaction.id == 3 then
				russia.luaData.crisis = russia.luaData.crisis +5
				--LogUi("ADDED!")
			end
		end	
		----- TERRITORY LOST ----------
		for hex in germany.hexes do
				if hex.originalFaction.id == 4 and game.turn >= 17 then
						russia.luaData.crisis = russia.luaData.crisis -5
				end	
		end
		for hex in austria.hexes do
				if hex.originalFaction.id == 4 and game.turn >= 17 then
						russia.luaData.crisis = russia.luaData.crisis -5
				end	
		end			

		--- SERBIA HELP DRAIN-----
		if GetEvent("SerbiaHelp") >0 then
			russia.luaData.crisis = russia.luaData.crisis - game.turn
		end
		--- OBSTINACY------
		if (player.alliance.id == 1 and game.type == Game.TYPE_SINGLE)
			or game.type == Game.TYPE_PBEM then
		if russia.luaData.obstinacy < game.turn then
			russia.luaData.crisis = russia.luaData.crisis - ((game.turn - russia.luaData.obstinacy) *2)
		end
		end
		
end
	


---- END CONDITIONS AND RECOVERY ------
if GetEvent("RussiaSupplyCrisis") > 0 
	
	and GetEvent("RussiaSupplyCrisis") + duration <= game.turn 
	and player.alliance.id == 1 
	and game.type == Game.TYPE_SINGLE 
	and impassable.luaData.winter == 0
	and GetEvent("RussiaSupplyCrisisEnd") == 0 
	and ((russia.luaData.warEffort <= 75 and GetEvent("RussiaSupplyCrisis") + duration <= game.turn)
			or (GetEvent("Polivanov") >0 
				and GetEvent("PolivanovDismissed") == 0
				and GetEvent("Polivanov") + math.random(2,4) <= game.turn 
				and math.random(1,10) < russia.luaData.collaps)) then
				
				SetEvent("RussiaSupplyCrisisEnd", game.turn)
					if russia.morale <= 65 and russia.morale >45 then
						ChangeFactionMorale(russia, game.turn)					
					elseif russia.morale <= 45 then
						ChangeFactionMorale(russia, game.turn*2)
					end
							ui.resourcesPanel:Refresh()



elseif ((GetEvent("RussiaSupplyCrisis") > 0 
		and GetEvent("RussiaSupplyCrisisEnd") == 0
		and GetEvent("RussiaSupplyCrisis") + duration <= game.turn  
		and impassable.luaData.winter == 0 ) 
		
		or (GetEvent("RussiaSupplyCrisis") > 0 
			and GetEvent("RussiaSupplyCrisisEnd") == 0 
			and GetEvent("Polivanov") >0 
			and GetEvent("PolivanovDismissed") == 0 
			and math.random(1,10) < russia.luaData.collaps))  then

			SetEvent("RussiaSupplyCrisisEnd", game.turn)
			if russia.morale <= 40 then
				ChangeFactionMorale(russia, 20)
			elseif russia.morale <= 50 then
				ChangeFactionMorale(russia, 15)	
			end
			ui.resourcesPanel:Refresh()

end	
	
if GetEvent("RussiaSupplyCrisisEnd") > 0  then
		if GetEvent("PolivanovDismissed") >0 and russia.luaData.warEffort < 85 then
			russia.luaData.warEffort = russia.luaData.warEffort + math.random(0,2)  
		
		elseif russia.luaData.warEffort < 85 then
			russia.luaData.warEffort = russia.luaData.warEffort + math.random(1,2) + math.random(1,2)  
		end
end

if GetEvent("RussiaSupplyCrisisEnd") > 0  
	and  GetEvent("RussiaSupplyCrisisEnd") +2 <= game.turn  then
		Discard("MurmanRailway")
		Discard("MurmanConvoys")
end


if GetEvent("RussiaSupplyCrisisEnd") > 0  
	and  GetEvent("RussiaSupplyCrisisEnd") +4 <= game.turn  then
		Discard("Polivanov")
		Discard("PolivamovDismissed")
end

end
Curiously, when I reload the "end turn" autosave file, the game never crashes :| I can't find where the error is... any idea about it?

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1230
Joined: Tue Nov 23, 2010 3:35 pm

Re: Any idea to fix this crash?

Post by Robotron » Sat May 18, 2019 8:40 pm

The script itself seems in order.

What happens when you remove the "conquer bonus" part that causes the crash?
Slitherine's Commander the Great War on steroids: POTZBLITZ mod!
http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: Any idea to fix this crash?

Post by Kossatx » Sun May 19, 2019 10:18 pm

I'll make a test removing the "conquer bonus" as you say.

Post Reply

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