From ab0e9faf14204f1537ec095657519478227b121d Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 23 Oct 2022 21:00:58 +0200 Subject: [PATCH] in custom functions that use variables: set the right prefix --- custom_functions_you_can_override.lua | 16 +++++++++++----- quest_api.lua | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/custom_functions_you_can_override.lua b/custom_functions_you_can_override.lua index 24b84ec..ed8d1ad 100644 --- a/custom_functions_you_can_override.lua +++ b/custom_functions_you_can_override.lua @@ -212,10 +212,12 @@ yl_speak_up.custom_functions_p_[ "compare_variable_against_variable" ] = { end local pname = player:get_player_name() local owner = yl_speak_up.npc_owner[ n_id ] + local prefix = "$ "..tostring(owner).." " -- get the value of the variable - -- the owner is alrady encoded in the variable name - local var_val_1 = yl_speak_up.get_quest_variable_value(pname, p.p_param1) - local var_val_2 = yl_speak_up.get_quest_variable_value(pname, p.p_param2) + -- the owner is usually alrady encoded in the variable name - but not here, so + -- we need to add it manually + local var_val_1 = yl_speak_up.get_quest_variable_value(pname, prefix..p.p_param1) + local var_val_2 = yl_speak_up.get_quest_variable_value(pname, prefix..p.p_param2) -- the comparison function below takes its parameters mostly in the form -- of entries in the table tmp_precon - thus, we construct a table with -- fitting entries @@ -420,8 +422,10 @@ yl_speak_up.custom_functions_r_[ "set_variable_to_random_number" ] = { end local new_value = math.random(n1, n2) -- the owner is already encoded in the variable name - local ret = yl_speak_up.set_quest_variable_value(pname, r.r_param1, new_value) local pname = player:get_player_name() + local owner = yl_speak_up.npc_owner[ n_id ] + local prefix = "$ "..tostring(owner).." " + local ret = yl_speak_up.set_quest_variable_value(pname, prefix..r.r_param1, new_value) local o_id = yl_speak_up.speak_to[pname].o_id or "?" yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." ".. "state: Success: "..tostring(ret).." for setting "..tostring(r.r_param1).." to ".. @@ -448,8 +452,10 @@ yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = { end local new_value = liste[math.random(1, #liste)] -- the owner is already encoded in the variable name - local ret = yl_speak_up.set_quest_variable_value(pname, r.r_param1, new_value) local pname = player:get_player_name() + local owner = yl_speak_up.npc_owner[ n_id ] + local prefix = "$ "..tostring(owner).." " + local ret = yl_speak_up.set_quest_variable_value(pname, prefix..r.r_param1, new_value) local o_id = yl_speak_up.speak_to[pname].o_id or "?" yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." ".. "state: Success: "..tostring(ret).." for setting "..tostring(r.r_param1).." to ".. diff --git a/quest_api.lua b/quest_api.lua index 5744cf0..856d151 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -35,14 +35,14 @@ yl_speak_up.load_quest_variables = function() io.input(file) local text = io.read() -- all values saved in the tables as such are strings - local data = minetest.parse_json(text, -1) + local data = minetest.parse_json(text, "$NIL_VALUE$") io.close(file) if(type(data) ~= "table") then return end for k,v in pairs(data) do - if(v == -1) then + if(v == "$NIL_VALUE$") then data[ k ] = {} end end