Et-win Posted August 11, 2014 Share Posted August 11, 2014 (edited) 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 August 11, 2014 by Guest Link to comment
Bonsai Posted August 11, 2014 Share Posted August 11, 2014 As far as I can see, cAdd is only nil when you first use it. So after that it is supposed to be removing and adding on every use? I'm not sure If I understand your problem Link to comment
Moderators IIYAMA Posted August 11, 2014 Moderators Share Posted August 11, 2014 Line 6: Comparing nil with false. Nil isn't the same as false, except they act the same. removeCommandHandler returns false/true. Best solution: if cAdd then Link to comment
Et-win Posted August 11, 2014 Author Share Posted August 11, 2014 (edited) 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 August 11, 2014 by Guest Link to comment
Max+ Posted August 11, 2014 Share Posted August 11, 2014 how about using somthing like this ? if ( cAdd == true ) then --- do something elseif ( cAdd == false ) then -- do something 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