Jump to content

bindKey bad argument ? :s


DarkLink

Recommended Posts

Guys i am trying to use a bind key to turn on and off lights of vehicle.. but it says always on console : bad argument @ 'bindKey '

i have this code for bindKey :

  
bindKey ( keyPresser, "l", "down", VehicleLights ) 
  

can u guys explain me what i am doing wrong ?

thanks.

Edit: VehicleLights is my other function that turn on and off lights .

Link to comment

you can't just put that,

you have to put:

  
addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (keyPresser, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (keyPresser, "l", "down", VehicleLights ) 
end 
end) 
  

So when the player joins they could press the button.

Link to comment

wrong,

addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (keyPresser, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (keyPresser, "l", "down", VehicleLights ) 
end 
end) 

keyPresser is not defined,

you should

addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (source, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (player, "l", "down", VehicleLights ) 
end 
end) 

Link to comment

keyPresser is player argument, was you know that ?

Try to do add something like

function onPlayerJoinBind () 
  bindKey ( source, "l", "down", VehicleLights ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), onPlayerJoinBind  ) 
  
function onResourceStartBind  () 
  for i,v in ipairs ( getElementsByType("player")) do 
  bindKey ( v, "l", "down", VehicleLights ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStartBind ) 
  

EDIT: someone was before me..

EDIT2: Why you guys unbinding key on start?

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