Jump to content

add- and removeEventHandler


Et-win

Recommended Posts

function functionname() 
    --Blablabla test function. 
end 
  
function testje() 
    if (cAdd ~= nil) then 
        cRemove = removeCommandHandler("test1", functionname) 
    end 
    cAdd = addCommandHandler("test1", functionname) 
    outputChatBox(tostring(cRemove)) 
    outputChatBox(tostring(cAdd)) 
end 
  
testje() 
addCommandHandler("testen", testje) 

function functionname() 
    --Blablabla test function. 
end 
  
function testje() 
    if (cAdd ~= nil) then 
        cRemove = removeCommandHandler("test1", functionname) 
    end 
    setTimer(function() 
        cAdd = addCommandHandler("test1", functionname) 
    end, 50, 1) 
    outputChatBox(tostring(cRemove)) 
    outputChatBox(tostring(cAdd)) 
end 
  
testje() 
addCommandHandler("testen", testje) 

By using the command: First time using it: it gets not removed but it gets added. Just like how it's supposed to work. Using it the second time: It gets removed and it gets NOT added. Third time: It gets not removed, but it gets added. Fourth time: It gets removed, but NOT added. Fifth: etc.

I bet someone knows why the first explanation doesn't work, but the second does. Bug, or...?

Point of this script:

By startup setting the command. As soon as you go to the 'Settings Panel' you can set your own commands. As soon as you click 'Save', this function gets started. It gets the old commands which are saved in variables (Not shown in this function). It removes the addCommandHandler with this variable and then sets the new one. The problem is: It will remove the old ones, but not add the new ones. This only works with the timer!

Edited by Guest
Link to comment

First usage = not removing, because it was never set before. Useless to remove it then. It's about the second time and up, just like I said:

First time using it: it gets not removed but it gets added. Just like how it's supposed to work.
Edited by Guest
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...