From 573753b80d5f79e2722df1a1a540c9f6cbb645f1 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 9 May 2021 16:51:24 +0200 Subject: [PATCH] report multiple dialog results and refuse edit in such a disambigous case --- functions.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/functions.lua b/functions.lua index b511c09..a0f4561 100644 --- a/functions.lua +++ b/functions.lua @@ -2531,6 +2531,43 @@ minetest.register_on_player_receive_fields( ) +-- identify multiple results that lead to target dialogs +yl_speak_up.check_for_disambigous_results = function(n_id, pname) + local errors_found = false + local dialog = load_dialog(n_id) + -- nothing defined yet - nothing to repair + if(not(dialog.n_dialogs)) then + return + end + -- iterate over all dialogs + for d_id, d in pairs(dialog.n_dialogs) do + if(d_id and d and d.d_options) then + -- iterate over all options + for o_id, o in pairs(d.d_options) do + if(o_id and o and o.o_results) then + local dialog_results = {} + -- iterate over all results + for r_id, r in pairs(o.o_results) do + if(r.r_type == "dialog") then + table.insert(dialog_results, r_id) + end + end + if(#dialog_results>1) then + minetest.chat_send_player(pname, "ERROR: Dialog ".. + tostring(d_id)..", option "..tostring(o_id).. + ", has multiple results of type dialog: ".. + minetest.serialize(dialog_results)..". Please ".. + "let someone with npc_master priv fix that first!") + errors_found = true + end + end + end + end + end + return errors_found +end + + minetest.register_on_player_receive_fields( function(player, formname, fields) if formname ~= "yl_speak_up:talk" then @@ -2637,6 +2674,13 @@ minetest.register_on_player_receive_fields( minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_master priv.") return end + -- the staff allows to create multiple target dialogs as result; this makes no sense + -- and is too disambigous + if(yl_speak_up.check_for_disambigous_results(n_id, pname)) then + -- this needs to be fixed by someone with a staff; we don't know which dialog is the right + -- result + return + end -- enter edit mode with that particular NPC yl_speak_up.edit_mode[pname] = yl_speak_up.speak_to[pname].n_id -- start a new chat - but this time in edit mode