I'm trying to record the time and IF a button is pressed. Every single time my variable table (it's a string) comes back blank. Why? I've tried with multiple people proficient in Lua and no one can tell me why it doesn't work. This was on a fresh gamemode (sandbox) too.
CLIENTSIDE:
[CODE]include( "shared.lua" )
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")
MyTabs = vgui.Create( "DPropertySheet", PanelTable.base )
MyTabs:SetPos( 10, 30 )
MyTabs:SetSize( 1700, 900 )
MyTabs:AddSheet( "Main", FirePanel, nill, false, false, "Fire here" )
FirePanel = vgui.Create("DPanel", MyTabs)
FirePanel:SetSize(1700, 900)
FirePanel:SetPos(10,30,1)
FirePanel:SetPaintBackground( false )
PanelTable.Button1 = vgui.Create( "DButton", FirePanel )
PanelTable.Button1:SetSize(200, 100)
PanelTable.Button1:SetPos(10,10,3)
PanelTable.Button1:SetText( "Button 1" )
PanelTable.Button1.DoClick = function (self)
self.Pressed = true
self.TimePressed = CurTime()
end
PanelTable.Button2 = vgui.Create( "DButton", 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.TimePressed = CurTime()
end
PanelTable.Button3 = vgui.Create( "DButton", FirePanel )
PanelTable.Button3:SetSize(200, 100)
PanelTable.Button3:SetPos(440,10,3)
PanelTable.Button3:SetText( "Button 3" )
PanelTable.Button3.DoClick = function (self)
self.Pressed = true
self.TimePressed = CurTime()
end
// PanelTable.button1 = vgui.Create("DButton", PanelTable.base)
function PanelTable.base:OnClose()
panels = FirePanel:GetChildren()
if panels then
local pressedbuttons = {}
PrintTable(panels)
for k, v in pairs(panels) do
if v:GetClassName() == "DButton" then
local button2 = { v:GetText() }
if v.Pressed and v.TimePressed then
table.insert(button2, v.TimePressed)
end
table.insert(pressedbuttons, button2)
end
end
net.Start("SendPressedButtons")
net.WriteTable(pressedbuttons)
net.SendToServer()
end
end
end
concommand.Add("instructorpanel", CreatePanel)
function ClearTable()
PanelTable = {}
end
[/CODE]
SERVERSIDE :
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
util.AddNetworkString("PanelClosed")
net.Receive("PanelClosed", function(len, ply)
local buttons = net.ReadTable()
for k, v in pairs(buttons) do
-- K is the name of the button (the text that you see)
-- V is if the button is pressed or not
file.Write( "Logfile.txt" , buttons )-- So, log stuff in here
end
end)
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 .. "[" .. os.date("%m/%Y", v[2]) .. "]" .. "The button " .. v[1] .. " was pressed\n"
else
TextToWrite = TextToWrite .. "[NONE] The button " .. v[1] .. " was not pressed\n"
end
end
ply:ChatPrint("Did it work... " .. TextToWrite)
if file.Exists("person/" .. ply:UniqueID() .. ".txt", "DATA") then
file.Append("person/" .. ply:UniqueID() .. ".txt", "\n\n" .. TextToWrite)
else
file.Write("person/" .. ply:UniqueID() .. ".txt", TextToWrite)
end
file.Write("helpme.txt", TextToWrite)
end)[/CODE]
You can see a chat message when I was trying to diagnose the problem. It prints : [QUOTE]1 = Panel: [name:Label][class:Label][10,10,200,100]
2 = Panel: [name:Label][class:Label][220,10,200,100]
3 = Panel: [name:Label][class:Label][440,10,200,100]
[/QUOTE] But I'm not sure how to use it...the file is never generated unless I manually do it like I did at the end (serverside). Even then, it gets update but it is always blank telling me the table I am using is always blank. I've tried ptuting the FirePanel inside the Paneltable and that doesn't change things
please help guys, I don't know how to debug this and I am going to pull out my hair and that's like my best feature.
File.Write generates a new file and adds the string to passed to it IIRC. So your serverside for loop in the PanelClosed net.receive just creates logfile.txt X number of times with a different string each time. Instead you should use file.Append.
[QUOTE=Exho;48767343]File.Write generates a new file and adds the string to passed to it IIRC. So your serverside for loop in the PanelClosed net.receive just creates logfile.txt X number of times with a different string each time. Instead you should use file.Append.[/QUOTE]
Would that explain why its blank though?
[QUOTE=Exho;48767343]File.Write generates a new file and adds the string to passed to it IIRC. So your serverside for loop in the PanelClosed net.receive just creates logfile.txt X number of times with a different string each time. Instead you should use file.Append.[/QUOTE]
He is not looping throught file.Write all the time, hes only looping by the table, adding some text to the string, and finally writing it, so that if the file exists, it should append it, and if it doesnt, it writes it instead
[editline]27th September 2015[/editline]
Oh, you mean the first net.Receive, in there youre right
Sorry, you need to Log In to post a reply to this thread.