From 676baa4b0bb44a6064d57c7d2e953450f1c95f2b Mon Sep 17 00:00:00 2001 From: upsilon Date: Sat, 11 Feb 2017 15:44:53 +0100 Subject: [PATCH] Check for NaN values in settings --- moremesecons_commandblock/init.lua | 2 ++ moremesecons_jammer/init.lua | 2 ++ moremesecons_playerkiller/init.lua | 2 ++ moremesecons_sayer/init.lua | 8 ++++++-- moremesecons_teleporter/init.lua | 4 ++++ moremesecons_wireless/init.lua | 2 ++ settingtypes.txt | 12 ++++++------ 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/moremesecons_commandblock/init.lua b/moremesecons_commandblock/init.lua index 9885ae0..0c33517 100644 --- a/moremesecons_commandblock/init.lua +++ b/moremesecons_commandblock/init.lua @@ -2,6 +2,8 @@ local function initialize_data(meta) local NEAREST_MAX_DISTANCE = tonumber(minetest.setting_get("moremesecons_commandblock.nearest_max_distance")) or 8 if NEAREST_MAX_DISTANCE <= 0 then NEAREST_MAX_DISTANCE = 1 + elseif NEAREST_MAX_DISTANCE ~= NEAREST_MAX_DISTANCE then -- NaN + NEAREST_MAX_DISTANCE = 8 end local commands = meta:get_string("commands") diff --git a/moremesecons_jammer/init.lua b/moremesecons_jammer/init.lua index 67e8e4c..7898e8e 100644 --- a/moremesecons_jammer/init.lua +++ b/moremesecons_jammer/init.lua @@ -19,6 +19,8 @@ local function is_jammed(pos) local JAMMER_MAX_DISTANCE = tonumber(minetest.setting_get(moresecons_jammer.max_distance)) or 10 if JAMMER_MAX_DISTANCE <= 0 then JAMMER_MAX_DISTANCE = 1 + elseif JAMMER_MAX_DISTANCE ~= JAMMER_MAX_DISTANCE then -- NaN + JAMMER_MAX_DISTANCE = 10 end local pz,py,px = vector.unpack(pos) diff --git a/moremesecons_playerkiller/init.lua b/moremesecons_playerkiller/init.lua index 45bbfaf..54ae332 100644 --- a/moremesecons_playerkiller/init.lua +++ b/moremesecons_playerkiller/init.lua @@ -2,6 +2,8 @@ local kill_nearest_player = function(pos) local MAX_DISTANCE = tonumber(minetest.setting_get("moremesecons_playerkiller.max_distance")) or 8 -- Use this number to set maximal distance to kill if MAX_DISTANCE <= 0 then MAX_DISTANCE = 8 + elseif MAX_DISTANCE ~= MAX_DISTANCE then -- NaN + MAX_DISTANCE = 8 end -- Search the nearest player diff --git a/moremesecons_sayer/init.lua b/moremesecons_sayer/init.lua index 8dab207..71c023c 100644 --- a/moremesecons_sayer/init.lua +++ b/moremesecons_sayer/init.lua @@ -44,9 +44,11 @@ if use_speech_dispatcher then end function sayer_activate(pos) - local MAX_DISTANCE = minetest.setting_get("moremesecons_sayer.max_distance") or 8 + local MAX_DISTANCE = tonumber(minetest.setting_get("moremesecons_sayer.max_distance")) or 8 if MAX_DISTANCE <= 0 then MAX_DISTANCE = 1 + elseif MAX_DISTANCE ~= MAX_DISTANCE then -- NaN + MAX_DISTANCE = 8 end MAX_DISTANCE = MAX_DISTANCE^2 @@ -83,9 +85,11 @@ if use_speech_dispatcher then end else function sayer_activate(pos) - local MAX_DISTANCE = minetest.setting_get("moremesecons_sayer.max_distance") or 8 + local MAX_DISTANCE = tonumber(minetest.setting_get("moremesecons_sayer.max_distance")) or 8 if MAX_DISTANCE <= 0 then MAX_DISTANCE = 1 + elseif MAX_DISTANCE ~= MAX_DISTANCE then -- NaN + MAX_DISTANCE = 8 end local tab = { diff --git a/moremesecons_teleporter/init.lua b/moremesecons_teleporter/init.lua index 8878761..0172796 100644 --- a/moremesecons_teleporter/init.lua +++ b/moremesecons_teleporter/init.lua @@ -13,10 +13,14 @@ local teleport_nearest = function(pos) local MAX_TELEPORTATION_DISTANCE = tonumber(minetest.setting_get("moremesecons_teleporter.max_t2t_distance")) or 50 if MAX_TELEPORTATION_DISTANCE <= 0 then MAX_TELEPORTATION_DISTANCE = 1 + elseif MAX_TELEPORTATION_DISTANCE ~= MAX_TELEPORTATION_DISTANCE then -- NaN + MAX_TELEPORTATION_DISTANCE = 50 end local MAX_PLAYER_DISTANCE = tonumber(minetest.setting_get("moremesecons_teleporter.max_p2t_distance")) or 25 if MAX_PLAYER_DISTANCE <= 0 then MAX_PLAYER_DISTANCE = 1 + elseif MAX_PLAYER_DISTANCE ~= MAX_PLAYER_DISTANCE then -- NaN + MAX_PLAYER_DISTANCE = 25 end -- Search the nearest player diff --git a/moremesecons_wireless/init.lua b/moremesecons_wireless/init.lua index 0e9a744..effcf97 100644 --- a/moremesecons_wireless/init.lua +++ b/moremesecons_wireless/init.lua @@ -117,6 +117,8 @@ function is_jammed(pos) local JAMMER_MAX_DISTANCE = tonumber(minetest.setting_get("moremesecons_wireless.jammer_max_distance")) or 15 if JAMMER_MAX_DISTANCE <= 0 then JAMMER_MAX_DISTANCE = 1 + elseif JAMMER_MAX_DISTANCE ~= JAMMER_MAX_DISTANCE then -- NaN + JAMMER_MAX_DISTANCE = 15 end local pz,py,px = vector.unpack(pos) diff --git a/settingtypes.txt b/settingtypes.txt index 2bdb3fe..99a617a 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -5,19 +5,19 @@ moremesecons_commandblock.authorized_commands (Authorized commands) string tell # Maximum distance of the @nearest player -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_commandblock.nearest_max_distance (Nearest player maximum distance) float 8 [Signal Jammer] # Jammer action range -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_jammer.max_distance (Jammer action range) float 10 [Player Killer] # Player Killer action range -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_playerkiller.max_distance (Player Killer action range) float 8 [Sayer] @@ -31,13 +31,13 @@ moremesecons_playerkiller.max_distance (Player Killer action range) float 8 moremesecons_sayer.use_speech_dispatcher (Use the Speech Dispatcher) bool true # Sayer range -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_sayer.max_distance (Range) float 8 [Teleporter] # Maximum Teleporter To Teleporter distance -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_teleporter.max_t2t_distance (Maximum Teleporter To Teleporter distance) float 50 # Maximum Player To Teleporter distance @@ -47,5 +47,5 @@ moremesecons_teleporter.max_p2t_distance (Maximum Player To Teleporter distance) [Wireless] # Wireless Jammer action range -# Any value less than or equal to 0 will be set to 1 +# Any value less than or equal to 0 will be changed to 1 and a NaN value will be changed to the default value moremesecons_wireless.jammer_max_distance (Wireless Jammer action range) float 15