Jump to content

unbindkey help


boro

Recommended Posts

Hi all please help i try make gui, it work fine but i dont know how to set unbindkey

This work only for open

bindKey('F4','down', 
    function ( ) 
guiSetVisible (GUIEditor_Window[1],true) 
showCursor (true) 
end 
) 

And next time i try this and guy dont open why ?

please help

bindKey('F4','down', 
    function ( ) 
guiSetVisible (GUIEditor_Window[1],true) 
showCursor (true) 
end 
  
unbindKey('F4','down', 
    function ( ) 
guiSetVisible (GUIEditor_Window[1],false) 
showCursor (false) 
end 
) 

Link to comment

Because that doesn't make any sense, you don't want to unbind, you want to hide the window when it's open.

bindKey ( 'F4', 'down', 
    function ( ) 
        local state = ( not guiGetVisible ( GUIEditor_Window[1] ) ) 
        guiSetVisible ( GUIEditor_Window[1], state ) 
        showCursor ( state ) 
    end 
) 

Link to comment

try this

bindKey("F4", "down", 
function () 
    local IsWindowVisible = guiGetVisible(GUIEditor_Window[1]) 
    if (IsWindowVisible == true) then 
        guiSetVisible(GUIEditor_Window[1], false) 
        showCursor(false) 
    end 
    if (IsWindowVisible == false) then 
        guiSetVisible(GUIEditor_Window[1], true) 
        showCursor(true) 
    end 
end 
) 

Link to comment

This way would probably work a little better, just a little less messy:

function windowAdjusting() 
    guiSetVisible(GUIEditor_Window[1], not guiGetVisible(GUIEditor_Window[1])) 
    showCursor(guiGetVisible(GUIEditor_Window[1])) 
end 
bindKey("F4","down",windowAdjusting) 

Link to comment
@ Solidsnake14 :

Qustion, Shouldn't be not state in your code ? ( at the showCursor function )

There is not already when defining the variable.

The problem here is that you can't unbind anonymous functions. You can do what {RoG}xXMADEXx suggested. This way you can use:

unbindKey( "F4", "down", windowAdjusting ); 

Link to comment

What i ment is in {RoG}xXMADEXx code the showCursor function's value is set to guiGetVisible, But if you use the state variable ( which as you said Already have not when defining in it. ) Then {RoG}xXMADEXx code should look like this :

    function windowAdjusting() 
        guiSetVisible(GUIEditor_Window[1], not guiGetVisible(GUIEditor_Window[1])) 
        showCursor(not guiGetVisible(GUIEditor_Window[1])) 
    end 
    bindKey("F4","down",windowAdjusting) 

But i know that this will revers the function, so how can it be correct ?

Link to comment

I'm not talking about his code but his method. You have to declare the function first and then bind it to a key so then you can unbind it.

His code will work properly since first he's setting gui visibility to opposite visibility state (if it's visible, not will make the return value: false = invisible), then he's getting the gui element visibility state to set the same to cursor. So, eg: hiding the gui first, then using the same visibility (guiGetVisible @ line 3) to cursor so hiding the cursor too.

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...