Can I stop empty/blank variable strings from defaulting to zero?

In MZ, If I put "" in a variable such as

$gameVariables.setValue(101, "");

and then use it in a message or choice using \v[101] it will be shown as 0 instead of empty/blank.

Even if I set an actor name to empty and set a variable to the actor's name it still becomes 0.
The only way I have found to use a blank is by directly calling the name using \n[x] instead of \v[x]

I know I was able to use "" in vxace, but I needed to designate it was a string not an interger
( $gameVariables[101] = "", or $gameVariables = whatever.to_s ) but I'm unsure if that works in MZ.

Is there still a way to read empty/blank strings by in variables in MZ?
JavaScript sees 0-length strings as falsy values, and the core scripts return 0 for the value of any game variable whose "real" value is falsy.

As a workaround, you could maybe store " " (single space) or "\u200b" (zero-width space) instead?
Edit: My suggestion won't work as the sanity checking is in the value function, not setValue.

caethyril's suggestion of setting it to a single or zero-width space should work.
You could tweak the value() method to accommodate this.

Paste this into a text editor, save as a *.js, include as a plugin.
Code:
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] === "" ? "" : this._data[variableId] || 0;
};
Edit: My suggestion won't work as the sanity checking is in the value function, not setValue.

caethyril's suggestion of setting it to a single or zero-width space should work.
Yeah $gameVariables._data[101] = ""; still results in 0. Thank you for trying though!

JavaScript sees 0-length strings as falsy values, and the core scripts return 0 for the value of any game variable whose "real" value is falsy.

As a workaround, you could maybe store " " (single space) or "\u200b" (zero-width space) instead?
I figured that the defaulting to 0 was some sort of safety default, but it is very bothersome. I'll try your work around in the meantime.
Thank you very much for helping me.

(The engine changing your inputs to things you didn't input is a real nightmare when trying to do anything complex!)

You could tweak the value() method to accommodate this.

Paste this into a text editor, save as a *.js, include as a plugin.
Code:
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] === "" ? "" : this._data[variableId] || 0;
};
You are a lifesaver!
Much appreciated! It works perfectly!

THANK YOU
Yeah $gameVariables._data[101] = ""; still results in 0. Thank you for trying though!


I figured that the defaulting to 0 was some sort of safety default, but it is very bothersome. I'll try your work around in the meantime.
Thank you very much for helping me.

(The engine changing your inputs to things you didn't input is a real nightmare when trying to do anything complex!)
It's kind of a necessary evil: by default variables have a value of "undefined" so if you tried displaying one before setting it to anything, it would literally print that instead of 0.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-stop-empty-blank-variable-strings-from-defaulting-to-zero.159797/