Jump to content

Short lua question


xScatta

Recommended Posts

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

Maybe like this?

removeEventHandler(eventName, source, handlerFunction) 

Wiki says

handlerFunction: 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

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

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