Add error messages when calling AddHog or AddMissionHog wrongly
authorWuzzy <Wuzzy2@mail.ru>
Mon, 20 May 2019 21:14:39 +0200
changeset 15017 d610d1c9fd55
parent 15016 ba49de0c0e38
child 15018 cf5d6ee109c9
Add error messages when calling AddHog or AddMissionHog wrongly
hedgewars/uScript.pas
--- 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);