Custom function and common event conflicts (?)

I have very simple and nothing special Common Event that displays Variable #4 using Yanfly's GAB window Plugin. This is nothing special for now, but the problem starts here:

I wrote simple function that renders my variable #4 to desired format (Ignore variable #20, with that it's OK):
Code:
HintKind = function(type, x){
    switch (type)
    {
        case 1 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[87]\\hc[32cd32]Hint:\\hc[ffffff]';
                }
        case 2 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[210]\\hc[87ceeb]New Item:\\hc[ffffff]';
                }
        case 3 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[191]\\hc[ffcc00]New Quest:\\hc[ffffff]';
                }
        case 4 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[90]\\hc[ffcc00]Quest Updated:\\hc[ffffff]';
                }
        case 5 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[90]\\hc[ffcc00]Quest Completed:\\hc[ffffff]';
                }
        case 6 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[17]\\hc[ff5757]Warning:\\hc[ffffff]';
                }
        case 7 :
                {
                    var p = ReadFile('./data/speech/hints.txt');
                    var r = Explode(p, "\n");
                    var s = Explode(r[x], "|");
                    $gameVariables.setValue(20, Number(s[1]));
                    return '\\c[6]' + s[0] + ':\\hc[ffffff] ' + s[2];
                }
        case 8 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[252]\\hc[c885ff]Skill Power increased:\\hc[ffffff]';
                }
        case 9 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[82]\\hc[98ff98]New Team Member:\\hc[ffffff]';
                }
        case 10 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[15]\\hc[ff813d]Critical Damage!!\\hc[ffffff]';
                }
        case 11 :
                {
                    $gameVariables.setValue(20, 0);
                    return '<center>\\i[312]\\hc[e3bb19]Level Up!\\hc[ffffff]';           
                }
    }
}

DisplayHint = function(type, hint){
    var a = HintKind(type, hint);
    if (type == 7)
    {
        $gameVariables.setValue(4, a);
    }
    else
    {
        $gameVariables.setValue(4, a + " " +  hint + "</center>");
    }
   
    $gameTemp.reserveCommonEvent(12);
    $gameTemp.clearCommonEvent(12);
   
}
The problem is when I call this function with Script Command like that - it only show last hint.
But when I set variable #4 with RMMV editor like that then everything is OK.

I could just ignore it and set hints with common events, but I'm planning (I have to) make a multilang option and custom, external functions would help me much. I have already made speech lines loaded from txt file and only hints left to fix.

At first I thought the problem might be with incompability with HIME's Common Event Queue Plugin but when I switched it off, my function DisplayHint() did not start common event #12 (ShowGameHints)

In case of your curiosity: Hint type 7 are speech lines of heroes in those section when they need to be in constant movement so I couldn't just simply use "Show Text" (There is a quest where a team needs to runaway from avalanche and I'm throwing classic one-liners like in action movies from '90s) event to NOT stop events processing.

PS: I provided links to Screenshots so drive your mouse cursor along text so you can find it (if you are using bright style)

PS #2 : I modified slighty GAB plugin so actor faces are loaded from variable 20 and that values are stored in text file. So that's why I told to ignore that variable.
I'm not sure I really understand what you're doing, but why do you have reserveCommonEvent followed immediately by clearCommonEvent? I would expect that would cause the common event to not run at all, because you're clearing it as soon as you reserve it.

Also, clearCommonEvent does not take an argument.
@Shaz, I just needed to organize some events I will need to run very often with different params/arguments therefore I wrote these functions.

Second thing. This clearing common event I found in google doc with MV script calls. But even if I delete that method clearCommonEvent() results are the same
Hello!
it's hard to say what's happening here. Out of curiosity, where is stored your function?
What if you remove the common event call from your function and just call the function to assigned value to variable 4 and then call the plugin command.
Code:
call function
GAB plugin commands
wait 120 frame
call function
GAB plugin commands
wait 120 frame
call function
GAB plugin commands
wait 120 frame
*I don't use Yanfly GAB window so I'm just guessing things here in a mere attempt to help a bit :dizzy: Sorry if it doesn't...
@TSR that actually works out. But I wanted to have it all in one function.

One function that sets variable and plays common event with plugin commands

Edit, OK I got it - I set event to parallel and now is ok, not exacly what I wanted but I can live with that.
In that case, I suggest you put some test variables. Maybe one variable that increase each time the function is call and another each time the common event run, and check if there's a difference because for what I read I'm guessing that the function is called 3 times but common event run only once...

Another way would be to check the plugin file and use the actual plugin methods for generating the GAB windows. So you could fully script the window in your function without depending on plugin commands and common events (But that just might be a little more tedious 😛)
@TSR Actually I also think there may be an issue with plugins, mostly with mine, because I'm still learning MV js framework - you can clearly see it in code - it's procedural, not object. But We may assume my problem is solved, I've just checked older maps in my project and all hint events are parallel and I forgot about that. So we are cool now. 🙂

Merry Christmas guys and thank you 🙂

Original thread: https://forums.rpgmakerweb.com/threads/custom-function-and-common-event-conflicts.116529/