How to make a string with spaces in a plugin command?

I'm making a plugin which shows text at different locations of the screen. 🙂

Unfortunately my approach was by plugin commands and my messages of course include spaces which makes the plugin think it as another argument.

Like I say: drawText My message with spaces 0 0
(STRING MESSAGE, X, Y)

I can't find any solutions..👋
1) have your plugins re-combine the arguments into a string. requires that the string is the last argument in the command, but a simple loop if it is.

2) you can try (no guarantee) to see if the default plugin command accepts "" as a declaration for a string argument
I'm making a plugin

my messages of course include spaces

if you're the author,..... maybe set it up so that strings are quoted and parameters are separated by commas? use parentheses? use colons?
IDK! you're the author! you can set it up however you want! 0o

drawText(string, param, param)
drawText: string, param, param.
drawText, "string", param, param.
drawText(param, param): "string"

so many variations.
More possibilities~
  • Ask users to type the message with a different character (e.g. underscore) instead of spaces, then do a global replace:
    Code:
    var msg = args[0].replace(/_/g, ' ');
    Global replace (MDN): link.

  • Rearrange the arguments to "x y text" and do something like this (basically Andar's first suggestion):
    Code:
    var x = parseInt(args[0], 10) || 0;
    var y = parseInt(args[1], 10) || 0;
    var msg = args.slice(2).join(' ');
    Array.slice (MDN): link.
    Edit: and Array.join (MDN): link. 😴
Thanks for all the replies!

I did it like this:

Code:
var text = args[0] + " ";
var i = 1;
var word;

while(!args[i - 1].includes(",")) {
if(args[i].includes(",")) {
word = args[i].slice(0, -1);
} else {
word = args[i] + " ";
}

text += word;
i++;
}

var x = Number(args[i + 1]);
var y = Number(args[i + 2]);

CreateMessage(text, x, y);

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-string-with-spaces-in-a-plugin-command.110687/