Drakath Posted February 28, 2015 Share Posted February 28, 2015 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
Ab-47 Posted February 28, 2015 Share Posted February 28, 2015 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
Drakath Posted February 28, 2015 Author Share Posted February 28, 2015 I need to do this with bindKey. Link to comment
Ab-47 Posted February 28, 2015 Share Posted February 28, 2015 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
Drakath Posted February 28, 2015 Author Share Posted February 28, 2015 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
TAPL Posted February 28, 2015 Share Posted February 28, 2015 There's two parameters you didn't put: function myFunction(key, keyState, marker) outputChatBox(marker) if isElement(marker) then doSomething() end end Link to comment
Drakath Posted February 28, 2015 Author Share Posted February 28, 2015 There's two parameters you didn't put: function myFunction(key, keyState, marker) outputChatBox(marker) if isElement(marker) then doSomething() end end Thank you, I did notice it somehow Link to comment
Ab-47 Posted February 28, 2015 Share Posted February 28, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now