I wanted to open the derma menu while the context key is held down and closed when released, instead the derma menu opens twice. What is this happening?
[CODE]
function jmenu()
if IsButtonDown == true then
local JFrame = vgui.Create("DFrame") --create a frame
JFrame:SetSize(250, 550) --set its size
JFrame:SetTitle("Take the weapon that you want") --set the title of the menu
JFrame:SetDraggable(true) --can you move it around
JFrame:SetSizable(false) --can you resize it?
JFrame:ShowCloseButton(true) --can you close it
JFrame:MakePopup() --make it appear
else
JFrame:Close()
end
end
hook.Add("OnContextMenuOpen", "contextmenuopen", function()
IsButtonDown = true
jmenu()
end)
hook.Add("OnContextMenuClose", "contextmenuclose", function()
local IsButtonDown = false
jmenu()
end)
[/CODE]
[CODE]
function jmenu()
if IsButtonDown == true then
local JFrame = vgui.Create("DFrame") --create a frame
JFrame:SetSize(250, 550) --set its size
JFrame:SetTitle("Take the weapon that you want") --set the title of the menu
JFrame:SetDraggable(true) --can you move it around
JFrame:SetSizable(false) --can you resize it?
JFrame:ShowCloseButton(true) --can you close it
JFrame:MakePopup() --make it appear
else
JFrame:Close()
end
end
hook.Add("OnContextMenuOpen", "contextmenuopen", function()
IsButtonDown = true
jmenu()
end)
hook.Add("OnContextMenuClose", "contextmenuclose", function()
local IsButtonDown = false
jmenu()
end)
concommand.Add("openmenu", jmenu
function KeyPressed (P, key)
P:ConCommand("openmenu")
end
hook.Add( "KeyPress", "KeyPressedHook", KeyPressed )
[/CODE]
[lua]concommand.Add( "+menu_context",function( ply,cmd,args,str )
--Open Derma
end )
concommand.Add( "-menu_context",function( ply,cmd,args,str )
--Close Derma
end )[/lua]
You use local variables incorrectly.
[code]
local IsButtonDown -- Make a variable that is only accessible from this file
function jmenu()
if IsButtonDown then -- No need to add == true
local JFrame = vgui.Create("DFrame") --create a frame
JFrame:SetSize(250, 550) --set its size
JFrame:SetTitle("Take the weapon that you want") --set the title of the menu
JFrame:SetDraggable(true) --can you move it around
JFrame:SetSizable(false) --can you resize it?
JFrame:ShowCloseButton(true) --can you close it
JFrame:MakePopup() --make it appear
else
JFrame:Close()
end
end
hook.Add("OnContextMenuOpen", "contextmenuopen", function()
IsButtonDown = true
jmenu()
end)
hook.Add("OnContextMenuClose", "contextmenuclose", function()
IsButtonDown = false -- Don't localize it here
jmenu()
end)[/code]
Ok, I'm getting a error when I release context key and the context menu seems to be stuck in context mode. Releaseing the key gives me the error below.
[IMG]http://snag.gy/TgKOU.jpg[/IMG]
Edit: I'm not sure why 'JFrame:Close()' isn't working.
[code]
local IsButtonDown -- Make a variable that is only accessible from this file
local JFrame
function jmenu()
if IsButtonDown then -- No need to add == true
JFrame = vgui.Create("DFrame") --create a frame
JFrame:SetSize(250, 550) --set its size
JFrame:SetTitle("Take the weapon that you want") --set the title of the menu
JFrame:SetDraggable(true) --can you move it around
JFrame:SetSizable(false) --can you resize it?
JFrame:ShowCloseButton(true) --can you close it
JFrame:MakePopup() --make it appear
else
JFrame:Close()
end
end
hook.Add("OnContextMenuOpen", "contextmenuopen", function()
IsButtonDown = true
jmenu()
end)
hook.Add("OnContextMenuClose", "contextmenuclose", function()
IsButtonDown = false -- Don't localize it here
jmenu()
end)[/code]
Because JFrame didn't exist outside of the if, that's what localized vars do, I suggest you read on that more.
Ok, I thought it was inside the loop.
This is the result:
[IMG]http://snag.gy/Wftio.jpg[/IMG]
I'll keep reading.
Are you calling it clientside only?
Yep, only clientside.
[editline]21st November 2013[/editline]
I made a mistake by localizing the derma menu. It's works perfect.
Sorry, you need to Log In to post a reply to this thread.