Drakath Posted February 28, 2015 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?
Ab-47 Posted February 28, 2015 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)
Ab-47 Posted February 28, 2015 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)
Drakath Posted February 28, 2015 Author 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
TAPL Posted February 28, 2015 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
Drakath Posted February 28, 2015 Author 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
Ab-47 Posted February 28, 2015 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.
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