Jump to content

Clientside bindKey


Drakath

Recommended Posts

Everything is client-side:

bindKey("h", "down", myFunction, source) 

source is a marker.

function myFunction(marker) 
    outputChatBox(marker) 
    if isElement(marker) then 
        doSomething() 
 end 
end 

This function outputs "h" and doesn't pass my marker so doSomething() is not executed. Why?

Link to comment

Calling a function like that is only server sided.

Try using triggerEvent for client sided functions.

Example:

  
function testFunc() 
    triggerEvent(source, "example.trigger") 
end 
addEventHandler("onClientResourceStart", root, testFunc) 
  
function trigger() 
    outputDebugString("called") 
end 
addEvent("example.trigger", true) 
addEventHandler("example.trigger", root, trigger) 
  

Link to comment
I need to do this with bindKey.

Yes, continue using bindKey and your code. But instead of calling "doSomething()" use this:

triggerEvent(source, "doSomething") 

Then to the function you're calling add it's events:

  
function doSomething() 
   --your code 
end 
addEvent("doSomething", true) 
addEventHandler("doSomething", root, doSomething) 
  

Link to comment

I think you misunderstood me, I don't care about doSomething(), I just put it as an example. You can call it whatever you want, the problem is that bindKey did not pass source:

function myFunction(marker) 
    outputChatBox(marker) --This outputs "h" 
    if isElement(marker) then --It doesn't pass this condition 
        outputChatBox("it worked") 
 end 
end 

Link to comment
I think you misunderstood me, I don't care about doSomething(), I just put it as an example. You can call it whatever you want, the problem is that bindKey did not pass source:

Sorry, I didn't understand your problem :3 and missed the point. But glad your situation is resolved.

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