Why won't this work?

This should work but i keep getting a string expected got a table error when trying to run it and the button won’t press or do anything!

[lua]-- for _, ent in ipairs(ents.GetAll()) do
– if ent:GetClass():find(“prop_physics”) then
– contents = file.Read(“my_mod/data.txt”)

-- end

– end
if(SERVER) then return; end
muse = 0
local start_html = [[
<html>
<head>
<style type=“text/css”>
body, html{
padding:0px 0px 0px 0px;
margin:0px 0px 0px 0px;
text-align: center;
vertical-align:100%;
height:100%;
}
</style>
</head>
<body scroll=“no”; bgcolor=“black”>
</body>
</html>
]]
–http.Get(“http://gamerfm.co.uk”, “”, httpCallBack)

local function Create_Browser2(contents, size)

--local offsets = Screen_Offsets[Entity:GetModel()]

--BW = offsets.w
--BH = offsets.h

--Scale = offsets.scale


Browser = vgui.Create( "HTML" )
    Browser:SetSize( 90, 90 )
    Browser:SetPaintedManually( true )
    Browser:SetVerticalScrollbarEnabled( false )
    Browser:SetHTML( contents )
    --Browser:StartAnimate( 1000 )

end
local function Create_Browser(ply, command, arguments)
–Browser:Remove( )
http.Get(arguments, “”, Create_Browser2)
–muse = 1
–else
–muse = 0
–contents = start_html
–end
end
–http.Get(“http://gamerfm.co.uk”, “”, Create_Browser)
concommand.Add( “playradio”, Create_Browser ) //Now we add a console command for the function we just created. It can be run straight from the console. If you look under the first couple of lines under init.lua, we

function radio2()
local steamid ={}
local DermaFrame = vgui.Create(“DFrame”)
DermaFrame:SetSize( 400, 285 )
DermaFrame:AlignLeft( 30 )
DermaFrame:AlignTop( 20 )
DermaFrame:SetTitle( “Adding Enforcers” ) – Title of the frame
DermaFrame:MakePopup()
local TestingComboBox = vgui.Create( “DComboBox”, DermaFrame )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false ) – Don’t use this unless you know extensive knowledge about tables

TestingComboBox:AddItem( “GamerFM” ) – Add our options
TestingComboBox:AddItem( “FragFM” )
TestingComboBox:AddItem( “BBC Radio 1” )
TestingComboBox:AddItem( “BBC Radio 2” )

– TestingComboBox:AddItem( “Add” ) – Add our options
– TestingComboBox:AddItem( “Some” )
– TestingComboBox:AddItem( “Options” )
– TestingComboBox:AddItem( “Here” )

local MainMenuSheet = vgui.Create( “DPanel”, DermaFrame ) – We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then – make sure something is selected if not we get uber spam of errors
–local OurStringThing = "Your selection is: “…TestingComboBox:GetSelectedItems()[1]:GetValue()…”! Which is: " … steamid[ TestingComboBox:GetSelectedItems()[1]:GetValue() ] – This was a pain in the ass to figure out; this gets the name of the option chosen
if TestingComboBox:GetSelectedItems()[1]:GetValue() == “GamerFM” then
local httpp = “http://gamerfm.co.uk
end
if TestingComboBox:GetSelectedItems()[1]:GetValue() == “FragFM” then
local httpp = “http://fragfm.co.uk/listen/
end
if TestingComboBox:GetSelectedItems()[1]:GetValue() == “BBC Radio 1” then
local httpp = “http://www.bbc.co.uk/iplayer/console/radio1
end
if TestingComboBox:GetSelectedItems()[1]:GetValue() == “BBC Radio 2” then
local httpp = “http://www.bbc.co.uk/iplayer/console/bbc_radio_two
end

local OurStringThing = "You selected the radio: "..TestingComboBox:GetSelectedItems()[1]:GetValue()

–local OurStringThing2 = "The Steam ID is: "… steamid[ TestingComboBox:GetSelectedItems()[1]:GetValue() ] – This was a pain in the ass to figure out; this gets the name of the option chosen
–local OurStringThing3 = “Are you sure you want to add this player as an Enforcer?”
surface.SetFont( “default” )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 30, 20 )
surface.DrawText( OurStringThing ) – Draws the text
–surface.SetTextPos( 30, 40 )
–surface.DrawText( OurStringThing2 ) – Draws the text
– surface.SetTextPos( 30, 70 )
– surface.DrawText( OurStringThing3 ) – Draws the text
local SystemButtonThingOne = vgui.Create(“DSysButton”, DermaFrame)
SystemButtonThingOne:SetPos( 110,50 )
SystemButtonThingOne:SetSize( 50, 25 )
SystemButtonThingOne:SetType( “close” ) – This can be “close”, “down”, or “up”
SystemButtonThingOne.DoClick = function()
RunConsoleCommand( "playradio " …httpp) – What happens when you press the button
end

end

end
end
concommand.Add( “radio2”, radio2 ) //Now we add a console command for the function we just created. It can be run straight from the console. If you look under the first couple of lines under init.lua, we[/lua]

how about… hmm give us the line where the error occures etc…? And this should go into the Newbie Question!


(User was banned for this post ("Backseat moderation" - mahalis))

Oops, didn’t realise!

The error is at line 28 and the button won’t click or do anything aswell in the vgui!

Are you sure that the line of the script in your post is the same as the lua file you are using?

Please tab your code in the future.

Here, this should fix most of your problems.



if(SERVER) then return end

muse = 0
local ahttp

local start_html = [[
<html>
    <head>
        <style type="text/css">
            body, html{
                padding:0px 0px 0px 0px;
                margin:0px 0px 0px 0px;
                text-align: center;
                vertical-align:100%;
                height:100%;            
            }
        </style>
    </head>
    <body scroll="no"; bgcolor="black">
    </body>
</html> 
]]

local function Create_Browser2(contents, size)

    Browser = vgui.Create( "HTML" )
    Browser:SetSize( 90, 90 )
    Browser:SetPaintedManually( true )
    Browser:SetVerticalScrollbarEnabled( false )
    Browser:SetHTML( contents )
    Browser:StartAnimate( 1000 )

end

local function Create_Browser(ply, command, arguments)

	http.Get(arguments[1], "", Create_Browser2) 
	
end

concommand.Add( "playradio", Create_Browser )

function radio2()

	local steamid ={}
	local DermaFrame = vgui.Create("DFrame")
	
	DermaFrame:SetSize( 400, 285 )
	DermaFrame:AlignLeft( 30 )
	DermaFrame:AlignTop( 20 )
	DermaFrame:SetTitle( "Adding Enforcers" )
	DermaFrame:MakePopup()
	
	local TestingComboBox = vgui.Create( "DComboBox", DermaFrame )
	TestingComboBox:SetPos( 10, 35 )
	TestingComboBox:SetSize( 100, 185 )
	TestingComboBox:SetMultiple( false )

	TestingComboBox:AddItem( "GamerFM" )
	TestingComboBox:AddItem( "FragFM" )
	TestingComboBox:AddItem( "BBC Radio 1" )
	TestingComboBox:AddItem( "BBC Radio 2" )

 	local SystemButtonThingOne = vgui.Create("DButton",  DermaFrame)
	SystemButtonThingOne:SetPos( 200,150 )
	SystemButtonThingOne:SetSize( 500, 250 )
	SystemButtonThingOne:SetVisible( false )
	SystemButtonThingOne.DoClick = function()
		RunConsoleCommand( "playradio",ahttp)
	end
	
	local MainMenuSheet = vgui.Create( "DPanel", DermaFrame )
	MainMenuSheet:SetPos( 125, 50 )
	MainMenuSheet:SetSize( 200, 50 )
	MainMenuSheet.Paint = function()
		if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then

			if TestingComboBox:GetSelectedItems()[1]:GetValue() == "GamerFM" then
				ahttp = "http://gamerfm.co.uk"
			end
			if TestingComboBox:GetSelectedItems()[1]:GetValue() == "FragFM" then
				ahttp = "http://fragfm.co.uk/listen/"
			end
			if TestingComboBox:GetSelectedItems()[1]:GetValue() == "BBC Radio 1" then
				ahttp = "http://www.bbc.co.uk/iplayer/console/radio1"
			end
			if TestingComboBox:GetSelectedItems()[1]:GetValue() == "BBC Radio 2" then
				ahttp = "http://www.bbc.co.uk/iplayer/console/bbc_radio_two"
			end
			local OurStringThing = "You selected the radio: "..TestingComboBox:GetSelectedItems()[1]:GetValue()
			SystemButtonThingOne:SetVisible( true )
			surface.SetFont( "default" )
			surface.SetTextColor( 255, 255, 255, 255 )
			surface.SetTextPos( 30, 20 )
			surface.DrawText( OurStringThing )
		end
    end

end
concommand.Add( "radio2", radio2 )


A quick look over it and there was a bunch of stuff wrong, can’t tell if I got it all.

Edit:

Also I made the button huge, might want to change that back :).

Oh, what did you fix and what was wrong with my code? i would like to know for future reference! :slight_smile:

All you end statements in the MainMenuSheet.Paint() function were in the wrong places, and you had your derma button in the paint function. Also,



local function Create_Browser(ply, command, arguments)

	http.Get(arguments[1], "", Create_Browser2) 
	
end


Arguments is a table containing all the arguments specified. We are only sending 1 string, so we do
arguments[1]. That grabs the first entry in the table, which is our string.

Read the wiki page for more info on concommands,
**[Concommand.Add

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Concommand.Add)**

hmmm, it appears to open the page succesfully but the music won’t play… though this might be my choice of radio shows. And the bbc ones don’t work anyway… So i might end up using gm_chrome if i can figure out how to use it…