show correct item in trade limit list when returning from editing an entry

This commit is contained in:
Sokomine 2022-09-05 07:27:29 +02:00
parent 15197a8861
commit a0f2f5b340

View File

@ -176,19 +176,14 @@ yl_speak_up.get_fs_trade_limit = function(player, selected)
-- the table event selection returns a row index - we need to translate that to our table
local item_list = {}
local descr_list = {}
for k,v in pairs( items ) do
table.insert(item_list, k)
end
-- avoid total chaos by sorting this list
table.sort(item_list)
local row = 2
local selected_row = 1
for i, k in ipairs( item_list ) do
local v = items[k]
if(selected and k == selected) then
selected_row = #item_list + 1
end
local c1 = '#FF0000'
if( v[1] > 0 ) then
c1 = '#BBBBBB'
@ -225,6 +220,10 @@ yl_speak_up.get_fs_trade_limit = function(player, selected)
yl_speak_up.speak_to[pname].trade_limit_items = items
yl_speak_up.speak_to[pname].trade_limit_item_list = item_list
table.insert(formspec, ";"..selected_row)
local selected_row = 1
if(selected and selected ~= "") then
selected_row = math.max(1, table.indexof(item_list, selected) + 1)
end
table.insert(formspec, ";"..selected_row.."]")
return table.concat(formspec, '')
end