Jump to content

[Question] bindKey problem


Recommended Posts

Hello, i've created a custom gui panel and wanted to bind a key to open it, and if it was open then the same button should close it.

But the problem is that it's only opening but not closing. i tried several ways like binding it with keyState "up" but instead i must hold the key for it to stay open.

I tried this way instead, it only opens it, without closing.

Code:

bindKey("o","down",function()
local visible = false
	if guiSetVisible(panelWindow,false) then
		guiSetVisible(panelWindow,true)
		showCursor(true)
		visible = true
		return visible
	end
	if visible == true then
		guiSetVisible(panelWindow,false)
		showCursor(false)
		visible = false
	end
end)

 

Link to comment

hi ๖ۣۜζ͜͡RapGod, i want to help you with this i will give you some code you should try this.

function toggleWindow()
   if(guiGetVisible(panelWindow) == false) then
      guiSetVisible(panelWindow, true)
      showCursor(true)
   else
      guiSetVisible(panelWindow, false)
      showCursor(false)
   end
end
bindKey("o", "down", toggleWindow)



You can check if the panel is visible with guiGetVisible() no variable needed

Edited by eoL|Shady
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...