Fix for crash

His Dad [08-08-18 - 07:59]
Fix for crash

Signed-off-by: His Dad <John@hisdad.org>
Filename
Doc/Changelog.txt
HistOffline.lua
history.txt
diff --git a/Doc/Changelog.txt b/Doc/Changelog.txt
index 3a71ebe..f2efb0d 100644
--- a/Doc/Changelog.txt
+++ b/Doc/Changelog.txt
@@ -1,3 +1,6 @@
+2018-08-08 version 50
+	The Toggle to hide characters that have completed all dungeons (Dungeon Mode) would crash the program if you had no vet characters.
+
 2018-08-03 version 49
 	Add Toggle to hide characters that have completed all dungeons (Dungeon Mode)

diff --git a/HistOffline.lua b/HistOffline.lua
index 1086969..18968a4 100644
--- a/HistOffline.lua
+++ b/HistOffline.lua
@@ -284,25 +284,27 @@ end
    --]]

    accounts[acc].char_tog = iup.toggle{ title = L.Characters}
+   accounts[acc].dung_tog = iup.toggle{ title = L.Dungeons}
+   accounts[acc].view_tog = iup.toggle{ title = L.View_Toggle, VISIBLE = "NO"}
+
   local tog = accounts[acc].char_tog
   function tog:action(x)
 	if x == 1 then
 	accounts[acc].mode_zbox.value =accounts[acc].char_tabs
-	iup.SetAttribute(view_tog, "VISIBLE", "NO")
+	iup.SetAttribute(accounts[acc].view_tog, "VISIBLE", "NO")
 	end
   end

-  accounts[acc].dung_tog = iup.toggle{ title = L.Dungeons}

   tog = accounts[acc].dung_tog
   function tog:action(x)
 	if x == 1 then
 	accounts[acc].mode_zbox.value = accounts[acc].dung_tabs
-	iup.SetAttribute(view_tog, "VISIBLE", "YES")
+	iup.SetAttribute(accounts[acc].view_tog, "VISIBLE", "YES")
 	end
   end

-  view_tog = iup.toggle{ title = L.View_Toggle, VISIBLE = "NO"}
+


   accounts[acc].mode = iup.frame {
@@ -313,14 +315,14 @@ end
 												accounts[acc].dung_tog,
 												},
 										},
-									view_tog,
+									accounts[acc].view_tog,
 									}
 								}

   accounts[acc].mode.title =  L.Mode
   accounts[acc].mode.margin = "15x5"

-  alldungeons = {}
+  accounts[acc].alldungeons = {}
   -- Prepare for Dungeon data recording as we iterate through characters.
   accounts[acc].dung = {}		-- put all dungeon mode stuff here. Populate it with character data.
   -- N Normal,   V Vet,    VH   Vet hard mode
@@ -329,20 +331,24 @@ end
   dung.pub.box = {}
   dung.pub.key = {}
   dung.pub.name = "pub"
-  table.insert(alldungeons,dung.pub)
-
+  table.insert(accounts[acc].alldungeons,dung.pub)
+
   dung.DLC = {}
   dung.DLC.box = {}
   dung.DLC.key = {}
   dung.DLC.name = "DLC"
-  table.insert(alldungeons,dung.DLC)
+  table.insert(accounts[acc].alldungeons,dung.DLC)
   dung.Grp = {}		-- these ones are indexed.
   dung.Trials = {}
+  tog = accounts[acc].view_tog

-    function view_tog:action(x)
+  function tog:action(x)
 		if x == 1 then   --hide completed columns
-			for _, ADung in pairs (alldungeons) do	-- for each dungeon
-			    print(ADung.name)
+			for _, ADung in pairs (accounts[acc].alldungeons) do	-- for each dungeon
+			    if (ADung.ShowColumn == nil)  then
+					print ("ADung.ShowColumn is nil for " .. ADung.name)
+					break
+				end
 				for col,show in pairs(ADung.ShowColumn) do
 					if show  then
 						iup.SetAttribute(ADung.box, "WIDTH"..tostring(col) ,"100")
@@ -352,12 +358,17 @@ end
 				end  --]]
 			end
 		else   -- show all
-			for _, ADung in pairs (alldungeons) do	-- for each dungeon
+			for _, ADung in pairs (accounts[acc].alldungeons) do	-- for each dungeon
+			    if (ADung.ShowColumn == nil)  then
+					print ("ADung.ShowColumn is nil for " .. ADung.name)
+					break
+				end
+
 				for col,show in pairs(ADung.ShowColumn) do
 						iup.SetAttribute(ADung.box, "WIDTH"..tostring(col) ,"100")
 				end
 			end
-		end
+		end
 	end

   -- Set up dungeon mode Group Dungeons
@@ -391,7 +402,7 @@ end
 		dung.Grp[i].box:setcell(0, col, playerNames[playerID])
 	end

-	table.insert(alldungeons,dung.Grp[i])
+	table.insert(accounts[acc].alldungeons,dung.Grp[i])
   end

   -- a table for each dungeon to which we add characters
@@ -453,7 +464,7 @@ end
 			dung.Trials[i].key[key][playerID] = false
 		  end
 		end
-		table.insert(alldungeons,dung.Trials[i])
+		table.insert(accounts[acc].alldungeons,dung.Trials[i])
   end


@@ -1209,21 +1220,6 @@ iup.Append(accounts[acc].char_tabs, accounts[acc].log_tab)

 	iup.SetAttribute(dung.DLC.box, "READONLY", "YES")

-	--[[
-	-- Populate with character data ============================
-	for line,key in ipairs(DLC2key) do		-- over each dungeon
-	    -- does that char exist in the table.
-		for i,playerID in ipairs(accounts[acc].playerIDs ) do	-- over each char in order
-			if dung.DLC.key[key][playerID] == nil then
-				dung.DLC.box:setcell(line,i, "N")
-				iup.SetAttribute(dung.DLC.box,"BGCOLOR" .. tostring(line) .. ":" .. tostring(i), BG_Colour_Not_Complete)
-			else
-				dung.DLC.box:setcell(line,i, "Y")
-				iup.SetAttribute(dung.DLC.box,"BGCOLOR" .. tostring(line) .. ":" .. tostring(i), BG_Colour_Complete)
-			end
-		end
-	end
-	--]]
 	populate(dung.DLC,DLC_Dat.key)


@@ -1236,8 +1232,8 @@ iup.Append(accounts[acc].char_tabs, accounts[acc].log_tab)
 	iup.Append(accounts[acc].dung_tabs, dung.DLC.tab)


-
-	if #accounts[acc].playerIDs_vet > 0  then  -- skip vet and trials if no eligible chars
+-- Commented out becase we expect all dung to be populated
+-- if #accounts[acc].playerIDs_vet > 0  then  -- skip vet and trials if no eligible chars

 		-- Create Trials  Tab ============================================
 		for _,i in ipairs (Trials_Order) do
@@ -1246,7 +1242,8 @@ iup.Append(accounts[acc].char_tabs, accounts[acc].log_tab)
 		--	print ("populate Trials")
 			populate(dung.Trials[i], Trials_Dat[i].key)
 		end
-	end -- has vet chars
+
+--end -- has vet chars

 end -- Accounts

diff --git a/history.txt b/history.txt
index 461986f..0904052 100644
--- a/history.txt
+++ b/history.txt
@@ -1,6 +1,6 @@
 ## Title: Dad's History
 ## APIVersion: 100023 100024
-## Version: 49
+## Version: 50
 ## Author: HisDad
 ## Description: Record progress of all characters for offline viewing.
 ## SavedVariables: History_SV