How to make a derma menu close automatically?

I’m having this weird bug with my weapons shop I’m making that the first time a player opens the shop and clicks on a weapon when they connect they get this error:
[ERROR] lua/includes/modules/usermessage.lua:87: attempt to call field ‘Function’ (a nil value)

  1. unknown - lua/includes/modules/usermessage.lua:87

The error is fixed when the menu is closed and then reopened, so I’m planning on just making it so that the shop automatically opens then instantly closes on player initial spawn but I’m not sure how to make the shop close. If anyone knows how to do this then please let me know.

Thanks in advance

function not Function

The error points back to a base gamemode file, [ERROR] lua/includes/modules/usermessage.lua:87
I’m not sure what is causing it in my code.

Here is the code in the base gamemode file it is pointing to:
[LUA]–[[---------------------------------------------------------
Name: Call( name, args )
Desc: Called by the engine to call a gamemode hook
-----------------------------------------------------------]]
function IncomingMessage( MessageName, msg )

if ( Hooks[ MessageName ] ) then

	Hooks[ MessageName ].Function( msg, unpack(Hooks[ MessageName ].PreArgs) )
	return

end

Msg("Warning: Unhandled usermessage '"..MessageName.."'

")

end[/LUA]

try verifying your cache or reinstalling gmod, you may have some corrupted/old files

I get errors that point back to base gamemode code all the time, but the problem is always with my code and I always fix the problem. The problem here is that I don’t know what is causing it in my code, so I’m just going to fix it the way I said in the original question but I need an answer of how to close a derma menu without someone clicking the close button.

[lua]
–[[---------------------------------------------------------
Name: Call( name, args )
Desc: Called by the engine to call a gamemode hook
-----------------------------------------------------------]]
function IncomingMessage( MessageName, msg )

if ( Hooks[ MessageName ] ) then

	Hooks[ MessageName ].Function( msg, unpack(Hooks[ MessageName ].PreArgs) )
	return

end

Msg("Warning: Unhandled usermessage '"..MessageName.."'

")

end
[/lua]
It looks like you have a usermessage hook cached but no function waiting to run. This is probably caused by usermessage.Hook(“hookname”) or something without a proper second argument.
Make sure you have a usermessage.Hook for all your umsg’s sent to the client.

Remember that this only happens the first time the shop is opened, once it is closed it is fine. All of my usermessages.hooks are defined, if they weren’t I would imagine it would give the error every time you clicked on a weapon in the shop and not just the first time the shop is opened. Does anyone know how you can close a derma panel automatically?

[editline]15th September 2013[/editline]

Ok, I think I finally found the answer to the mysterious question.
CloseDermaMenus()

I don’t know about all those errors and all that, but if you want the menu to open on initial spawn you can do this:

This goes in your init.lua file.
[lua]function GM:PlayerInitialSpawn ( ply )
umsg.Start (“indexme”, ply) – What to run and who to run it on. Obviously the player.
umsg.End ()
end [/lua]

And here’s where you’d put the actual usermessage.Hook since it needs something to call:

Put this in your cl_init.lua file.
[lua]
function Test ( )
– All your sexy derma and all that shit goes here.
end
usermessage.Hook (“indexme”, Test) – You call it via indexme and Test is what function to run.
[/lua]

So, the end result would be when players INITIALLY spawn, not respawn, it’ll call that usermessage.Hook and open your fancy derma menu and all that.

If you want it to close after they click a button or whatever you can do this:
[lua]
button.DoClick = function ( ) – Change button to whatever you named your DButton

base:Remove() – Change base to whatever you named your DFrame in local base = vgui.Create ( “DFrame” )

end
[/lua]

Make a DFrame all that. Make a DButton and SetParent to the DFrame and once you click the button it’ll remove the whole window.

OR if you prefer to do it with a timer you could do something like:

This code isn’t tested, although I do use it a lot and if I remember correctly this is how it’s done.

This will start a timer when you click your button and after 5 seconds it’ll run the function which removes the base aka closes everything.
[lua]
button.DoClick = function ( )

timer.Simple(5, function() – 5 is the time in seconds
base:Remove() – After 5 seconds this will run
end)

end
[/lua]

I’m sure you can figure out the rest. Just edit it to your liking. If this doesn’t help you hopefully it can help someone else.

This is what I was looking for, thank you. I don’t know why I couldn’t find it on the wiki.