Check for nil from SpawnCustomCrate
authornemo
Mon, 29 Aug 2011 19:28:45 -0400
changeset 5703 637fb1e6487b
parent 5702 944849ec04bf
child 5704 718f98a9df12
Check for nil from SpawnCustomCrate
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Mon Aug 29 23:56:38 2011 +0200
+++ b/hedgewars/uScript.pas	Mon Aug 29 19:28:45 2011 -0400
@@ -279,9 +279,9 @@
     else begin
         if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3)
         else health:= cHealthCaseAmount;
-        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            HealthCrate, health);
-        lua_pushinteger(L, gear^.uid);
+        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health);
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnhealthcrate := 1;        
 end;
@@ -294,9 +294,9 @@
         lua_pushnil(L);
     end
     else begin
-        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            AmmoCrate, lua_tointeger(L, 3));
-        lua_pushinteger(L, gear^.uid);
+        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3));
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnammocrate := 1;
 end;
@@ -311,7 +311,8 @@
     else begin  
         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
             UtilityCrate, lua_tointeger(L, 3));
-        lua_pushinteger(L, gear^.uid);
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnutilitycrate := 1;
 end;