From 035ecb2bd7a7e37889b7f13dc40e0344de6be96b Mon Sep 17 00:00:00 2001
From: Aaron Veden <veden@vedbyte.com>
Date: Mon, 21 Feb 2022 17:06:08 -0800
Subject: [PATCH] FACTO-56: added nil check for playerForces during migration

---
 changelog.txt | 2 ++
 control.lua   | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/changelog.txt b/changelog.txt
index 78f1f92..ab9cd7e 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -6,6 +6,8 @@ Version: 2.3.0
     - Added surface minime_dummy_dungeon and minime-preview-character to exclusion list
     - Increased unit spawner cooldown by 2x
     - Added point loss on unit death
+  Bugfixes:
+    - Fixed Krastorio2 on_force_created playerforces being nil
 
 ---------------------------------------------------------------------------------------------------
 Version: 2.2.0
diff --git a/control.lua b/control.lua
index 4a3dd46..bb762b5 100644
--- a/control.lua
+++ b/control.lua
@@ -848,7 +848,9 @@ local function onGroupFinishedGathering(event)
 end
 
 local function onForceCreated(event)
-    universe.playerForces[#universe.playerForces+1] = event.force.name
+    if universe.playerForces then
+        universe.playerForces[#universe.playerForces+1] = event.force.name
+    end
 end
 
 local function onForceMerged(event)