I've got a small but still annoying bug I want to fix in the Irina VisualNovelBusts plugin. (
https://atelieririna.itch.io/visual-novel-busts)
The Situation:
If I use the escape code \bustMsgExp[x, y] in a Show text event it switches the face used in bustslot x to y.
So if I make a showtext event like this:
Code:
\bust[1]This is a simple message.\BustMsgExp[1, 5]
It sets the current face picture to show as bust in Bust slot 1, prints "This is a simple message" and afterwards changes the face to expression 5.
That's working fine.
The Problem:
However if I write this code...
Code:
\bust[1]This is a simple message. \BustMsgExp[1, 5]
The game crashes and I get an error message.
My suspicion: the regular expression that's supposed to pick up \BustMsgExp doesn't get picked up correctly due to the white space confusing the process.
The error message itself refers as the problem happening in this line:
Code:
var expression=array[1].toUpperCase().trim();
Regardless of what comes first, toUpperCase or trim, the code immediately crashes.
I've set up a couple alert messages to get the contents of the array before the crash:
If it's working, the array returns:
array[0] = 1
array[1] = 5
array[2] = undefined (this array is not made use of, no issues)
The array[0] is the x in \BustMsgExp[x, y], the array[1] is the y.
But if I insert a whitespace:
array[0] =
(there is nothing in the array, not even undefined or 0. Just nothing)
array[1] = undefined
array[2] = undefined (as it should be)
The part of the code that parses into the array is this one:
Code:
if(code.match(/BUSTMSG(?:INDEX|EXP|EXPRESSION)/i)){var array=this.obtainVNBustMsgEscapeString(textState).split(",");
var sprite=$bust(parseInt(array[0]));
That's where array[0], the Bustslot, gets its ID assigned.
The part obtainVNBustMsgEscapeString leads back to this function that's used for all escape strings:
Code:
Window_Base.prototype.obtainVNBustMsgEscapeString=function(t){var e=/^\[(.*?)\]/.exec(t.text.slice(t.index));
if(e){t.index+=e[0].length;
return String(e[0].slice(1,e[0].length-1))}else{return""}};
Imported.Irina_VisualNovelBusts.Window_Message_initMembers=Window_Message.prototype.initMembers;
I don't know much about regular expressions, but my assumption is that somewhere in these two codes, there's something that causes a single whitespace to pick up the entirely wrong contents.
Can someone tell me where the problem is and how to fix it? I'd really like to ensure that a single whitespace won't cause crashes and that the plugin becomes more stable.