Need help keeping variables consistent.

I do my table.inserts (OUTSIDE) of the DoClick functions for button presses: , that way it also records when someone does NOT hit a button (critically important in my thing) … the problem is, they are still inside my Create Giant panel function and so their values get removed each time i open and close the panel… how should I solve this??


PanelTable = {}


 
function CreatePanel()
        PanelTable.base = vgui.Create("DFrame")
        PanelTable.base:SetSize(1800, 1000)
        PanelTable.base:SetPos(ScrW() / 2 - PanelTable.base:GetWide() / 2, ScrH() / 2 - PanelTable.base:GetTall() / 2)
        PanelTable.base:ShowCloseButton(true)
        PanelTable.base:MakePopup()
        PanelTable.base:SetVisible(true)
        PanelTable.base:SetDraggable(true)
        PanelTable.base:SetTitle("Instructor Panel")
       
        PanelTable.MyTabs = vgui.Create( "DPropertySheet", PanelTable.base )
        PanelTable.MyTabs:SetPos( 10, 30 )
        PanelTable.MyTabs:SetSize( 1700, 900 )
        PanelTable.MyTabs:AddSheet( "Main", PanelTable.FirePanel, nill, false, false, "Fire here" )
       
        PanelTable.FirePanel = vgui.Create("DPanel", PanelTable.MyTabs)
        PanelTable.FirePanel:SetSize(1700, 900)
        PanelTable.FirePanel:SetPos(10,30,1)
        PanelTable.FirePanel:SetPaintBackground( false )
       
        PanelTable.tblButtons = {}
        PanelTable.Button1 		= vgui.Create( "DButton", PanelTable.FirePanel )
        PanelTable.Button1:SetSize(200, 100)
        PanelTable.Button1:SetPos(10,10,3)
        PanelTable.Button1:SetText( "Begin Fire Scenario" )
        PanelTable.Button1.DoClick = function (self)
				start_time = CurTime()
                print ("Beginning Fire Scenario, clock started @" .. start_time)
        end
               
        PanelTable.Button2      = vgui.Create( "DButton", PanelTable.FirePanel )
        PanelTable.Button2:SetSize(200, 100)
        PanelTable.Button2:SetPos(220,10,3)
        PanelTable.Button2:SetText( "Button 2" )
        PanelTable.Button2.DoClick = function (self)
                self.Pressed = true
				self.Elapsed = CurTime() - start_time 
				print (self.Elapsed)
        end
        table.insert(PanelTable.tblButtons, PanelTable.Button2)

Left out a few buttons for unnessary space…


PanelTable.Button5      = vgui.Create( "DButton", PanelTable.FirePanel )
        PanelTable.Button5:SetSize(200, 100)
        PanelTable.Button5:SetPos(880,10,3)
        PanelTable.Button5:SetText( "End Scenario, 
Write Log" )
        PanelTable.Button5.DoClick = function ()
     
	                 panels = PanelTable.tblButtons
				
                if panels then
                         pressedbuttons = {}
                        for k, v in pairs(panels) do
                                 buttons = { v:GetText(), v.Pressed and v.Elapsed }
								
                                table.insert(pressedbuttons, buttons)
							PrintTable (buttons)	
                        end
                        net.Start("SendPressedButtons")
						
                                net.WriteTable(pressedbuttons)
                        net.SendToServer()
                end
        end
end

Serverside :


util.AddNetworkString("SendPressedButtons")
net.Receive("SendPressedButtons", function(len, ply)
        local PanelTable = net.ReadTable()
        if not PanelTable then return end
       
        local TextToWrite = ""
        for k, v in pairs(PanelTable) do
                if v[2] and isnumber(v[2]) then
											
                        TextToWrite = TextToWrite .. math.Round(v[2],2).. " The button " .. v[1] .. " was pressed
"
                else
                        TextToWrite = TextToWrite .. "[NONE] The button " .. v[1] .. " was not pressed
"
                end
        end
        
        file.Write("Log.txt", TextToWrite)
end)
 

It works great and is exactly the information I need. However, if I close and reopen the panel (which CANNOT be avoided) I will lose the value of the tables/variables. What is a good solution to this?

Create the variables outside the function, then change them inside. With this you probably can’t store them on the panels themselves. Don’t know if stored values reset with Hide, but if they don’t then you can also use Panel:Hide() and Popup instead of deleting and recreating them.

Thanks for the response. The problem though is they are being added to a table outside of the DoClick but inside the create panel function. If they were individual variables that would work but when I’m the same name, like Self.pressed?