pa3ck Posted January 17, 2014 Share Posted January 17, 2014 Hi there, I'm having trouble with my little code. It works, but for some reason it spams the chat and gives me an error saying that "C stack overflow" addEventHandler("onClientElementDataChange", root, function ( name, oldValue ) if getElementType(source) == "player" then local protected = getElementData(source, "protected") or 0 if protected == 0 then outputChatBox("Element data was changed back to old value.", 255, 0, 0) newValue = getElementData(source, name, value) setElementData(source, name, oldValue) end end end) Any help? Link to comment
DiSaMe Posted January 17, 2014 Share Posted January 17, 2014 Calling 'setElementData' triggers "onElementDataChange"/"onClientElementDataChange". If these events cause 'setElementData' to be called, you get an infinite recursion. You could make a variable that stops the execution of event handler if element data is being reverted. An example: local revertingData addEventHandler("onElementDataChange", root, function(dataname, oldvalue) if revertingData then return end revertingData = true setElementData(source, dataname, oldvalue) revertingData = nil end) 'setElementData' call in this handler will cause the same handler to be called recursively, but the checking of 'revertingData' variable will prevent the subsequent recursive calls. Link to comment
pa3ck Posted January 17, 2014 Author Share Posted January 17, 2014 Oh yea, you're right! Thanks! 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