How do common events interact with normal ones?

Hello, Apologies for making another post right after one was solved, but I've been stuck on this for about an hour and I'm not sure why this is happening.

As per my last post, I noted creating a script that'd change an event's sprite after a counter has gone up a certain amount of times:

JavaScript:
const loopChange = [[3 , 0],[6 , 1],[9 , 2]];

for (let animal in loopChange){
numTbl = loopChange[animal];
var trueNum = numTbl[0];
if (trueNum == ($gameVariables.value(1))){
let spriteId = numTbl[1]; $gameMap.event(16).setDirection(2); $gameMap.event(16).setImage("Actors1",spriteId); break;
} else if (loopChange.length - 1 != animal) { $gameMap.event(16).setDirection(2); $gameMap.event(16).setImage("",0);
} else {break; }}

The code does work, when it's placed on a normal event. But, when moving it to a common event, the script continues to mostly function but the target event's sprite never changes.

I did color out the sprite sheet to make sure it isn't just switching to an unintended sprite but this doesn't seem to be the case either as the event remains invisible.

so I know that the problem has to be something to do with how common events recognize normal events, I'm assuming the common event doesn't know what "$gameMap.event(16)" actually is.

I also came across a forum post whilst looking for solutions in which the solution described:
"When you use the Call Common Event command, the common event behaves as if it were a part of the calling event - it has that event's id, the map id that the calling event is on, etc."
so if this were the case, it'd know what map its on and from there refer to the correct event, but this doesn't seem to be happening unless I'm missing something?

again, to re-clarify. the code does work as intended when its not in a common event, I'm not sure why it breaks when inside a common event as I don't get any errors or anything. I'm aware this behavior doesn't require a script but I might as well see ends meet and get this fully functional instead of dropping it entirely.

Your help is appreciated!
Is it the same when you test it on that map, as when you test it not on that map?
Is it the same when you test it on that map, as when you test it not on that map?
It should work given it only relies on a single variable and a pre-existing event, moving the two would have the same effect on that new map


I've been messing around with it more and i've noticed that it's only the first character sprites which seems to not appear now, the other two seem to work as intended.

i've read somewhere that == and === operators are used to prevent / allow data from being converted from one type to another (so a string of "1" and an interger of 1), so I thought that the code was converting 0 to nil, but I can't use the == / === operators on "spriteId = numTbl[1];" so i'm not sure if it's actually doing that or not. -- apparently it's not this either, I had the script detect if the table value was 0 then set it to sprite 0 and it still remains invisible, so i'm lost again

not the elseif statement either, removing that still has that first sprite invisible
Update -- I've resolved this problem,

can't believe it was over the silliest thing too; the event that was supposed to have its image changed had a variable condition that wouldn't let it do anything until the loop counter hit 3. Despite the first change happening when the loop does change on 3, this seems to have been why the sprite's image would never change on the first loop count, disabling this variable (it was unnecessary, unsure why i toggled it) has resolved the problem.

Thank you for helping! 👍
This thread is closed due to being reported as solved. If you need it reopened, report it to let us know.

The “report” button can be found at the bottom of your post box and will send the thread directly to our queue if you need assistance. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/how-do-common-events-interact-with-normal-ones.177948/