# HG changeset patch # User Wuzzy # Date 1558379679 -7200 # Node ID d610d1c9fd557fc893b74c33055509a449ca91b6 # Parent ba49de0c0e38c1990d90903934128df8706b065b Add error messages when calling AddHog or AddMissionHog wrongly diff -r ba49de0c0e38 -r d610d1c9fd55 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);