From 10e4e9157b8951dc94614fcd369661efd2005bab Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 4 Aug 2016 01:32:06 +0200 Subject: Fix crash in empty categories --- init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 7835757..69bd908 100644 --- a/init.lua +++ b/init.lua @@ -49,7 +49,7 @@ function doc.mark_entry_as_viewed(playername, category_id, entry_id) doc.data.players[playername].stored_data.viewed[category_id] = {} doc.data.players[playername].stored_data.viewed_count[category_id] = 0 end - if doc.data.players[playername].stored_data.viewed[category_id][entry_id] ~= true then + if doc.entry_exists(category_id, entry_id) and doc.data.players[playername].stored_data.viewed[category_id][entry_id] ~= true then doc.data.players[playername].stored_data.viewed[category_id][entry_id] = true doc.data.players[playername].stored_data.viewed_count[category_id] = doc.data.players[playername].stored_data.viewed_count[category_id] + 1 -- Needed because viewed entries get a different color @@ -258,6 +258,8 @@ function doc.formspec_category(id, playername) formstring = formstring .. "label[0,0.5;This category has the following entries:]" formstring = formstring .. doc.generate_entry_list(id, playername) formstring = formstring .. "button[0,8;3,1;doc_button_goto_entry;Show entry]" + formstring = formstring .. "label[8,8;Number of entries: "..doc.get_entry_count(id).."\n" + formstring = formstring .. "New entries: "..(doc.get_entry_count(id)-doc.get_viewed_count(playername, id)).."]" end return formstring end -- cgit v1.2.3