Jump to content

[help]bindKey() and unBindKey()

Guest d1sch4rg3d

Recommended Posts

local bind = 1 
function pJoin() 
    bindKey( source, "arrow_r", "down", cSelect ) 
addEventHandler( "onPlayerJoin", getRootElement(), pJoin ) 
function onpSpawn() 
    if ( bind == 1 ) then 
        unBindKey( source, "arrow_r", "down", cSelect ) 
        bind = 0 
addEventHandler( "onPlayerSpawn", getRootElement(), onpSpawn ) 

I have the bind variable, because i do not want this code to unbind every time the player spawns. I want it to run just the first time he spawns.

Everything works fine, but i get this error.

"Attempt to call global 'UnBindKey' "

Could someone please help. I'd appreciate it very much. Thanks :]

Link to comment

You have one global variable bind. Whenever a player spawns another player will have the key bound even when he spawns, why? Because that one global variable is 0. You don't have to use that global var to check if the key was bound. You can use isKeyBound() to check if the key "arrow_r" is bound already.. then you can unbindKey if isKeyBound() returned true.

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