hedgewars/uScript.pas
changeset 15038 d610d1c9fd55
parent 14948 9d6a25239d00
child 15053 b181ff6367c9
--- a/hedgewars/uScript.pas	Mon May 20 16:53:52 2019 +0200
+++ b/hedgewars/uScript.pas	Mon May 20 21:14:39 2019 +0200
@@ -2630,7 +2630,10 @@
         hatName:= lua_tostring(L, 4);
         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
         ParseCommand('hat ' + hatName, true, true);
-        lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
+        if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
+            lua_pushnumber(L, CurrentHedgehog^.Gear^.uid)
+        else
+            OutError('Lua error: AddHog: Error adding hog. Maybe function was called outside of onGameInit.', true);
         end
     else
         lua_pushnil(L);
@@ -2655,7 +2658,10 @@
             ParseCommand('addhh ' + IntToStr(BotLevel) + ' ' + lua_tostring(L, 1) + ' ' + Name, true, true);
             ParseCommand('hat ' + hatName, true, true);
             end;
-        lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
+        if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
+            lua_pushnumber(L, CurrentHedgehog^.Gear^.uid)
+        else
+            OutError('Lua error: AddMissionHog: Error adding hog. Maybe function was called outside of onGameInit.', true);
         end
     else
         lua_pushnil(L);