From bd67fa2ea7a155f86963b37d637cd254fed21a61 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 26 Feb 2023 22:41:32 +0100 Subject: [PATCH] add d_end in migration script when necessary --- yl_local_server_do_on_reload.lua | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/yl_local_server_do_on_reload.lua b/yl_local_server_do_on_reload.lua index 55a76ec..2133f9a 100644 --- a/yl_local_server_do_on_reload.lua +++ b/yl_local_server_do_on_reload.lua @@ -79,20 +79,33 @@ yl_speak_up.check_one_npc_for_migration = function(dialog, pname, n_id) -- sometimes we need d_end because minetest.close_formspec in -- an effect of type "function" is not enough elseif(has_close_formspec) then + local found = false local d_old = "" for r_id, r in pairs(o.o_results) do - if(r.r_type == "dialog" and r.r_value ~= "d_end") then + if(r.r_type == "dialog" and not(found)) then d_old = r.r_value r.r_value = "d_end" + found = true end end - yl_speak_up.save_dialog(n_id, dialog) - local msg = "ERROR: Dialog ".. - tostring(d_id)..", option "..tostring(o_id).. - ", uses minetest.close_formspec in its lua code ".. - "but "..tostring(d_old).." instead of d_end as ".. - "target dialog. Fixing." - minetest.chat_send_player(pname, msg) + -- if there is no dialog option yet: create one + if(not(found)) then + local future_r_id = yl_speak_up.add_new_result( + dialog, d_id, o_id) + o.o_results[future_r_id] = { + r_id = future_r_id, + r_type = "dialog", + r_value = "d_end"} + end + if(d_old ~= "d_end") then + yl_speak_up.save_dialog(n_id, dialog) + local msg = "ERROR: Dialog ".. + tostring(d_id)..", option "..tostring(o_id).. + ", uses minetest.close_formspec in its ".. + "lua code but "..tostring(d_old).. + " instead of d_end as target dialog. Fixing." + minetest.chat_send_player(pname, msg) + end end end if(o_id and o and o.o_prerequisites) then