xScatta Posted August 8, 2016 Share Posted August 8, 2016 Hey guys! Is there a way to get "source Function" ? Like this -- in timer now we can get his source by sourceTimer setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) -- and it will outputChatBox only once And the question is: Can we get the function variable without a name like this addEventHandler("onPlayerClick",some player, function (button,state) if button == "left" and state == "down" then outputChatBox("you triggered the event only once! u can't do it anymore!") removeEventHandler(eventName,source,sourceFunction) -- here is what i want to know end end,false) Because it would be faster way to use. Waiting for some help! Link to comment
ozulus Posted August 8, 2016 Share Posted August 8, 2016 Maybe like this? removeEventHandler(eventName, source, handlerFunction) Wiki sayshandlerFunction: The handler function you wish to call when the event is triggered. This function will be passed all of the event's parameters as arguments, but it isn't required that it takes all of them. Link to comment
xScatta Posted August 8, 2016 Author Share Posted August 8, 2016 I think u dont understand me, i want to create a local function without a name in the event handler. Not to create new one with name. Someone can help tho? Link to comment
Rataj Posted August 8, 2016 Share Posted August 8, 2016 Did you try it like this? local sourceTimer = setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) Or rather use this: local sourceTimer function someFunction() sourceTimer = setTimer(timerFunction, 1000, 5) end function timerFunction() outputChatBox("1") killTimer(sourceTimer) end Link to comment
qaisjp Posted August 8, 2016 Share Posted August 8, 2016 Did you try it like this? local sourceTimer = setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) That won't work, but this might: local sourceTimer sourceTimer = setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) Link to comment
Rataj Posted August 8, 2016 Share Posted August 8, 2016 Did you try it like this? local sourceTimer = setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) That won't work, but this might: local sourceTimer sourceTimer = setTimer(function () outputChatBox("1") killTimer(sourceTimer) end, 1000, 5) Yeah, I was thinking about this too later. Try it. Link to comment
xScatta Posted August 11, 2016 Author Share Posted August 11, 2016 Guys im not talking about the timer, the timer was the example....., im talking about sourceFunction in event, when i don't name the function, can i get it from a variable? Link to comment
novo Posted August 11, 2016 Share Posted August 11, 2016 Only predefined variables are these, and thus what you are trying to achieve is not possible. Link to comment
zneext Posted August 12, 2016 Share Posted August 12, 2016 As novo said there's not a predefined variable with that value, But you can obtain the "source function" using debug.getinfo: local sourceFunction = debug.getinfo( 1, "f" ).func however the easiest solution is naming the function. Link to comment
xScatta Posted August 12, 2016 Author Share Posted August 12, 2016 Thanks @znext, i was searching for something like that! 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