PDA

View Full Version : Functions overriden twice



xelab
September 21st, 2022, 17:47
Hi I am trying to correclty save old references and call them in overridden functions however I get some sort of recursion:



function onInit()
-- save the old ref
oldRef = SomeModule.SomeFunction;

-- replace the function reference with new code
SomeModule.SomeFunction= new_function;
end

function new_function()
Debug.chat("1")
oldRef()
end


whenever SomeModule.SomeFunction gets called I get "1" twice in the chat (and the function is executed twice)

however if I "hard" override the function e.g.

function onInit()
-- replace the function reference with new code
SomeModule.SomeFunction= new_function;
end

function new_function()
Debug.chat("1")
-- <just copy paste the old code here>
end


I only get "1" once in the chat and the function in only executed once.

What could this be?

xelab
September 21st, 2022, 20:02
Sorry to have bothered, I have figured it out. My script was sourced in two places, in extension.xml, and in another .xml file, that is onInit was called twice leading to this recursive behavior.