Prevent non-initialized wagons from accidentally polluting the world
authororwell96 <mono96.mml@gmail.com>
Tue, 10 Jan 2017 21:54:10 +0000 (22:54 +0100)
committerorwell96 <mono96.mml@gmail.com>
Tue, 10 Jan 2017 21:54:10 +0000 (22:54 +0100)
sometimes wagons get created/loaded but are not initialized. These stand around and can't be removed.
Now if a wagon does not get initialized after 20 steps, something went wrong and the wagon is removed.

advtrains/advtrains/init.lua
advtrains/advtrains/wagons.lua

index 03ec553..a415857 100644 (file)
@@ -34,8 +34,8 @@ local function print_concat_table(a)
        end
        return str
 end
---atprint=function() end
-atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end
+atprint=function() end
+--atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end
 sid=function(id) return string.sub(id, -4) end
 
 dofile(advtrains.modpath.."/helpers.lua");
index bedffda..13811ad 100644 (file)
@@ -151,8 +151,17 @@ function wagon:init_shared()
        end\r
 end\r
 function wagon:ensure_init()\r
-       if self.initialized then return true end\r
-       self.object:setvelocity({x=0,y=0,z=0})\r
+       if self.initialized then\r
+               if self.noninitticks then self.noninitticks=nil end\r
+               return true\r
+       end\r
+       if not self.noninitticks then self.noninitticks=0 end\r
+       self.noninitticks=self.noninitticks+1\r
+       if self.noninitticks>20 then\r
+               self.object:remove()\r
+       else\r
+               self.object:setvelocity({x=0,y=0,z=0})\r
+       end\r
        return false\r
 end\r
 \r