foobar
foobar

Reputation: 2941

Lua Error: attempt to index global 'concommand' (a nil value)

I want to make a simple web browser in lua. I got the following script. But its not compiling and giving error : attempt to index global 'concommand' (a nil value) Can anyone tell whats wrong with my script?

    -- Simple Web Browser by Drunkie

if SERVER then AddCSLuaFile("web_browser.lua") return end

concommand.Add( "OpenWebBrowser", function()

local homepage = "http://www.google.com"

local frame = vgui.Create( "DFrame" )
frame:SetSize( ScrW()*0.8, ScrH()*0.8 )
frame:SetTitle( "" )
frame:SetDraggable( false )
frame:Center()
frame:MakePopup()
frame.Paint = function()
    surface.SetDrawColor( 0, 0, 0, 150 )
    surface.DrawRect( 0, 0, frame:GetWide(), frame:GetTall() )
end

local lbl_loading = vgui.Create( "DLabel", frame )
lbl_loading:SetText( "Loading . . ." )
surface.CreateFont( "coolvetica", 64, 400, true, false, "LoadFont" )
lbl_loading:SetFont( "LoadFont" )
lbl_loading:SetColor( Color( 255, 255, 255 ) )
lbl_loading:SizeToContents()
lbl_loading:Center()

local html_pos = { 12, 48 }
local html_size = { frame:GetWide()-html_pos[1]*2, frame:GetTall()-html_pos[2]-html_pos[1] }
local html_frame = vgui.Create( "HTML", frame )
html_frame:SetPos( html_pos[1], html_pos[2] )
html_frame:SetSize( html_size[1], html_size[2] )
html_frame:OpenURL( homepage )

local lbl_goto = vgui.Create( "DLabel", frame )
lbl_goto:SetText( "Goto:" )
surface.CreateFont( "coolvetica", 24, 400, true, false, "GotoFont" )
lbl_goto:SetFont( "GotoFont" )
lbl_goto:SetColor( Color( 255, 255, 255 ) )
lbl_goto:SetPos( 12, 16 )
lbl_goto:SizeToContents()

local txt_goto = vgui.Create( "DTextEntry", frame )
txt_goto:SetSize( frame:GetWide()-96, 24 )
txt_goto:SetPos( 64, 14 )
txt_goto:SetText( homepage )
txt_goto.OnEnter = function()
    local site = string.lower( txt_goto:GetValue() )
  --      if string.Left( site, 7 ) != "http://" then
  --         site = "http://" .. site
  --      txt_goto:SetText( site )
  --  end
    html_frame:OpenURL( site )
end

end )

Upvotes: 0

Views: 2065

Answers (2)

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26609

That script is from 2010, while Garry made some API changes to Garry's Mod in 2012/13. It's unlikely that the script will work as-is.

Also, I would agree with Schollii to not start programming with Garry's Mod. The API is not very good.

Upvotes: 0

Oliver
Oliver

Reputation: 29621

I was unable to follow your wiremod link (need login to download). But looks like this script is supposed to be run from within some application that embeds Lua to make itself scriptable (I think gmod http://www.garrysmod.com/). You can't just run the script on its own: several of the variables you see in this script are linked to data in the host application.

To create a web browser iike the script does, you will have to install that application. Alternately, drop this approach and start with something simpler and more fun, like Corona which uses Lua, it will be much better documented and have more community support.

Upvotes: 2

Related Questions