summaryrefslogtreecommitdiff
path: root/mesecons_pistons
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2013-06-22 15:43:58 -0400
committerAnthony Zhang <azhang9@gmail.com>2013-06-22 15:43:58 -0400
commit96011bc71816b5e9eb2cc6c86f009198dfb1146c (patch)
treea3ded974dcfc8aca8f6b9837e5a4d571a84e680d /mesecons_pistons
parentec63bd3abfdca2a77b7945834a9b37f7533a4e27 (diff)
downloadmesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar
mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.gz
mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.bz2
mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.xz
mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.zip
Audit code for possible nil value indexing with unregistered nodes.
Diffstat (limited to 'mesecons_pistons')
-rw-r--r--mesecons_pistons/init.lua31
1 files changed, 16 insertions, 15 deletions
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index f044d5a..1284eb7 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -46,7 +46,7 @@ piston_facedir_direction = function (node)
return rules[1]
end
-piston_get_direction = function (dir, node)
+piston_get_direction = function(dir, node)
if type(dir) == "function" then
return dir(node)
else
@@ -54,25 +54,26 @@ piston_get_direction = function (dir, node)
end
end
-local piston_remove_pusher = function (pos, node)
+local piston_remove_pusher = function(pos, node)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
+ if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
+ return
+ end
dir = piston_get_direction(pistonspec.dir, node)
local pusherpos = mesecon:addPosRule(pos, dir)
local pushername = minetest.env:get_node(pusherpos).name
- if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
- minetest.env:remove_node(pusherpos)
- minetest.sound_play("piston_retract", {
- pos = pos,
- max_hear_distance = 20,
- gain = 0.3,
- })
- nodeupdate(pusherpos)
- end
+ minetest.env:remove_node(pusherpos)
+ minetest.sound_play("piston_retract", {
+ pos = pos,
+ max_hear_distance = 20,
+ gain = 0.3,
+ })
+ nodeupdate(pusherpos)
end
-local piston_on = function (pos, node)
+local piston_on = function(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
local dir = piston_get_direction(pistonspec.dir, node)
@@ -91,10 +92,10 @@ local piston_on = function (pos, node)
end
end
-local piston_off = function (pos, node)
+local piston_off = function(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
- piston_remove_pusher (pos, node)
+ piston_remove_pusher(pos, node)
if pistonspec.sticky then
dir = piston_get_direction(pistonspec.dir, node)
@@ -104,7 +105,7 @@ local piston_off = function (pos, node)
end
end
-local piston_orientate = function (pos, placer)
+local piston_orientate = function(pos, placer)
-- not placed by player
if not placer then return end