Did you come right. Sorry I have not been on the forum for a while.
Can you send the code that calls these 2 functions pls.
Is the ‘onSame’ function called before the ‘duplicar’ function?
Also, the loc, forn & ref variables are not passed to the ‘onSame’ function. So it would modify the global variables of the same name, or those variables in the function that calls ‘onSame’.
Do you understand the SCOPE of variables?
If a program is like a filing cabinet( let’s name it MainCabinet), then:-
Global variables are visible to all drawers and hanging files in MainCabinet.
A function (let’s name it FnDrawer), called from MainCabinet is like a drawer in the filing cabinet.
A function’s variables are visible to all hanging files in the drawer (FnDrawer) in which it resides.
A function (let’s name it SubFunction), called from FnDrawer is visible to itself and any functions it calls. You could think of envelopes inside the hanging files, for the functions called by SubFunction.
A hanging file in the top drawer cannot access or modify variables in the 2nd drawer.
A hanging file in a drawer can only show it’s variables to the drawer by RETURNING them (which you have done in ‘onSame’). But, which variables are being changed by ‘onSame’? No parameters are being passed to it, so it is modifying the variables from it’s calling function (or global, if you made those 3 variables global).
Check the scope of your variables in your functions.
Tip: you can change the loc to loc1 in a certain function, just to clarify in your mind, which loc you are referring to (same with the other 2 variables).
loc1 = firstvalue; forn1 etc
loc2 = all that good stuff (don’t change the good stuff, okay)
loc = all that other good stuff (as required in your challenge)
In ‘duplicar’, you passed the 3 variables to it as loc, forn and ref. So no change needed there.
In ‘onSame’, nothing is passed. Just saying. I think I’m repeating myself now. I’ll let you have a go at it . . . .