Help me understand this scoreboard hook.

Someone gave me this skeleton


local scoreimage = scoreimage or {}
function scoreimage:show()
	local frame = vgui.Create("DFrame")
	--setpos
	frame:SetPos( 400, 300 )
	frame:SetSize( 200,200 )
	function scoreimage:hide()
		frame:SetVisible(false)
	end
end

hook.Add("ScoreboardShow", "quickref", function()
	scoreimage:show()

	print "scoreboard hook success"
end)

hook.Add("ScoreboardHide", "quickref", function()
	scoreimage:hide()
end)


I can’t figure out what to do next? I’m trying to get an imge/panel to appear…the hook obviously works because I get the print message in console. Am I supposed to draw the panel in the hook itself (like underneath print). It is odd, it draws a panel but when I change the size or position the console gives " attempt to index global ‘scoreimage’ (a nil value)"

Point me in the right direction please.
"

Not underneath print, just inside the show() function I gave you… it is not hard to understand it, as an example, parent the image to the frame, and try it, and give me your full code with the image, so I can see it myself.

[editline]22nd August 2015[/editline]

also, make the 2nd “quickref” to “quickref2” since you cant have 2 different hooks with the same name.

If you already have the panel made, change the vgui.Create( “DFrame” ) to vgui.Create( “PanelNamehere” ) as you’ve identified it in the file.

his old panelname was “quickreference” if I remember right, and it was setup wrong, and therefore gave errors, the given code from me was just an example.

Also you shouldn’t be using local for scoreboard frames unless they are components parented to the frame itself

if you really want, I can spoonfeed you the code, lol, I’d just need the image, and where it shall be.

[editline]22nd August 2015[/editline]

its an example code.

No above being spoodfed. Saying “ahh”

How can I give the image path in my gamemode folder (content) Where should it actually be? (how do you call/reference it when the path is relative to garrysmod/materials?

Right now it is in garrysmod/materials just for the time being while I am testing this

so yeah, assume the file is garrysmod/materials/image1.png

EDIT : My current cod, right now I am just trying to get the frame correct but it doesn’t change even when I have changed the position and size…



local scoreimage = scoreimage or {}
function scoreimage:show()
	local frame = vgui.Create("DFrame")
	
	frame:SetPos( 400, 300 )
	frame:SetSize( 400,400 )
	function scoreimage:hide()
		frame:SetVisible(false)
	end
end

hook.Add("ScoreboardShow", "quickref", function()
	scoreimage:show()

	print "scoreboard hook success"
end)

hook.Add("ScoreboardHide", "quickref2", function()
	scoreimage:hide()
	print "Scoreboard exit complete"
end)

an gamemode folder is afaik literally the same as an addon, except its an whole gamemode, so calling gamemode materials is relative to the materials folder etc. so you do like
image = “image1.png”

with where it shall be, I mean the pos of the image, duh.

[editline]22nd August 2015[/editline]

make sure the code is clientside, and try restarting the server.

That seems to be working, thanks a bunch for sticking with me.

Oh, how do I hide the player list?

EDIT: Google works sometimes guys:


function GM:ScoreboardShow()
end

function GM:ScoreboardHide()
end

EDIT: To anyone trying to learn this and finds this years after, remember


frame:SetVisible(false) 

	end

You have to also add your image variable to that so your image goes away too (anything that you are calling up earlier in your function)

to hide the image you dont have to set its visibility too, aslong as you set the parent the frame, everything that belongs to it will get hidden.

I’d recommend frame:Remove() instead of setting visible/invisible

it would be usefull when using MakePopup, since it would spam the console afterwards that there are too many panels, but afaik, its not really neccessary here, since theres no “popup”.

In your scoreboard you have defined a hide function which sets it invisible, however in the hook to show the scoreboard, you call the function that creates a new panel. You are essentially hiding the old one, but instead of showing it again, you create a new one while the old is still there invisible.