From 8ea4123e01c948ff0e0fbb9143e0e71427581ac1 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 4 Jul 2021 22:49:13 +0200 Subject: [PATCH] fixed bug in variable comparison --- fs_edit_preconditions.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs_edit_preconditions.lua b/fs_edit_preconditions.lua index 4d86d9c..021e2c2 100644 --- a/fs_edit_preconditions.lua +++ b/fs_edit_preconditions.lua @@ -290,11 +290,17 @@ yl_speak_up.eval_precondition = function(player, n_id, p) return var_val == nil -- for security reasons: do this manually instead of just evaluating a term elseif(p.p_operator == "==") then + if(p.p_var_cmp_value == nil) then + return false + end -- best do these comparisons in string form to make sure both are of same type return tostring(var_val) == tostring(p.p_var_cmp_value) elseif(p.p_operator == "~=") then return tostring(var_val) ~= tostring(p.p_var_cmp_value) elseif(p.p_operator == ">=") then + if(p.p_var_cmp_value == nil) then + return false + end -- compare numeric if possible if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then return tonumber(var_val) >= tonumber(p.p_var_cmp_value) @@ -303,30 +309,45 @@ yl_speak_up.eval_precondition = function(player, n_id, p) return tostring(var_val) >= tostring(p.p_var_cmp_value) end elseif(p.p_operator == ">") then + if(p.p_var_cmp_value == nil) then + return false + end if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then return tonumber(var_val) > tonumber(p.p_var_cmp_value) else return tostring(var_val) > tostring(p.p_var_cmp_value) end elseif(p.p_operator == "<=") then + if(p.p_var_cmp_value == nil) then + return false + end if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then return tonumber(var_val) <= tonumber(p.p_var_cmp_value) else return tostring(var_val) <= tostring(p.p_var_cmp_value) end elseif(p.p_operator == "<") then + if(p.p_var_cmp_value == nil) then + return false + end if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then return tonumber(var_val) < tonumber(p.p_var_cmp_value) else return tostring(var_val) < tostring(p.p_var_cmp_value) end elseif(p.p_operator == "more_than_x_seconds_ago") then + if(p.p_var_cmp_value == nil) then + return false + end if(not(tonumber(var_val)) or not(tonumber(p.p_var_cmp_value))) then return true end return (tonumber(var_val) + tonumber(p.p_var_cmp_value)) < math.floor(minetest.get_us_time()/1000000) elseif(p.p_operator == "less_than_x_seconds_ago") then + if(p.p_var_cmp_value == nil) then + return false + end if(not(tonumber(var_val)) or not(tonumber(p.p_var_cmp_value))) then return false end