• Issue with HTTP library?
    1 replies, posted
Hey guys, im having issues with my code, its either a) not reassigning a variable like it should or b) running the code in a funky order Im thinking it's b, and i was hoping somone could tell me why Code below: [lua] AddCSLuaFile() print("Loading music plugin ..") local NetworkStreamName = "RadioPluginMessage" local receiving_side = CLIENT function displayGui() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 500, 700 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaListView = vgui.Create("DListView") DermaListView:SetParent(DermaPanel) DermaListView:SetPos(25, 50) DermaListView:SetSize(450, 525) DermaListView:SetMultiSelect(false) DermaListView:AddColumn("Song Name, Value") -- Add column local NumSliderThingy = vgui.Create( "DNumberWang", DermaPanel ) NumSliderThingy:SetPos( 403,650 ) NumSliderThingy:SetMin( 0 ) NumSliderThingy:SetMax( 100 ) NumSliderThingy:SetText("Text") NumSliderThingy:SetDecimals( 0 ) local DLabel = vgui.Create( "DLabel", DermaPanel ) DLabel:SetPos( 350, 650 ) DLabel:SetText( "Volume" ) local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Play" ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand( "" ) -- What happens when you press the button end --for i=1,100 do -- DermaListView:AddLine("Test" .. i) --end local music = getMusicList() --for i=1,#music do --print(n,v) --DermaListView:AddLine(music[i]) --end end function getMusicList() local TheReturnedHTML = "nil" http.Fetch( "http://bots.zack6849.com/music/list.jsp", function( body, len, headers, code ) print("Success!") TheReturnedHTML = body end, function( error ) print("Error!", error) end ); print("returned ->", TheReturnedHTML) list = {} index = 1 for k,v in pairs(string.Split(TheReturnedHTML, " \n")) do print(k, v) end return list end if(receiving_side) then net.Receive(NetworkStreamName, function (len) local command = net.ReadString() print("command") if(command == "display") then displayGui() end end) else util.AddNetworkString(NetworkStreamName) function process(player, strText, bTeamOnly, bPlayerIsDead) if string.StartWith(string.lower(strText), "!music") then net.Start(NetworkStreamName) net.WriteString("display") net.Broadcast() end return true end hook.Add("PlayerSay", "TestHook", process) end [/lua] Console output command returned -> nil 1 nil [CS-D] zack6849: !music Success! Anyone know how i would fix this?
In your code, you have what's called "Callbacks". These are functions that are called when date is returned and such. Seeing as they aren't called at the same time as the rest of the code, you can't look at it in a linear fashion. I don't actually see why you are setting the variable inside the callback, instead of just calling your parser functions on it directly. Try the following: [lua] AddCSLuaFile() print("Loading music plugin ..") local NetworkStreamName = "RadioPluginMessage" local receiving_side = CLIENT local List = {} function displayGui() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 500, 700 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaListView = vgui.Create("DListView") DermaListView:SetParent(DermaPanel) DermaListView:SetPos(25, 50) DermaListView:SetSize(450, 525) DermaListView:SetMultiSelect(false) DermaListView:AddColumn("Song Name, Value") -- Add column local NumSliderThingy = vgui.Create( "DNumberWang", DermaPanel ) NumSliderThingy:SetPos( 403,650 ) NumSliderThingy:SetMin( 0 ) NumSliderThingy:SetMax( 100 ) NumSliderThingy:SetText("Text") NumSliderThingy:SetDecimals( 0 ) local DLabel = vgui.Create( "DLabel", DermaPanel ) DLabel:SetPos( 350, 650 ) DLabel:SetText( "Volume" ) local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( DermaPanel ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Play" ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () RunConsoleCommand( "" ) -- What happens when you press the button end --for i=1,100 do -- DermaListView:AddLine("Test" .. i) --end local music = getMusicList() for i=1,#List do DermaListView:AddLine(List[i]) end end function getMusicList() local TheReturnedHTML = "nil" http.Fetch( "http://bots.zack6849.com/music/list.jsp", function( body, len, headers, code ) print("Success!") for k,v in pairs(string.Split(body, " \n")) do print(k, v) List[k] = v end end, function( error ) print("Error!", error) end ); end if(receiving_side) then net.Receive(NetworkStreamName, function (len) local command = net.ReadString() print("command") if(command == "display") then displayGui() end end) else util.AddNetworkString(NetworkStreamName) function process(player, strText, bTeamOnly, bPlayerIsDead) if string.StartWith(string.lower(strText), "!music") then net.Start(NetworkStreamName) net.WriteString("display") net.Broadcast() end return true end hook.Add("PlayerSay", "TestHook", process) end [/lua]
Sorry, you need to Log In to post a reply to this thread.