forked from Sokomine/yl_speak_up
fixed bug in variable comparison
This commit is contained in:
parent
52267f0b2b
commit
8ea4123e01
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user