Alternative to defining functions in global space for script calls

In previous makers, I would create script calls that users could use like this

do_something( arg1, arg2, ... )I would like to do this as well in MV.Since the script call command is evaluated globally, I won't be able to assume it's evaluated in the context of the interpreter, so I can't simply add them to the interpreter's prototype.

Some have suggested to include it in my own namespace

Code:
TH.do_something( arg1, arg2)
But that just seems like a lot of extra typing for end-users and people may choose not to use it in favor of another plugin that doesn't force them to type so much.
For script commands, i don't really care how long they are. If you want easier options for the use, you can define plugin commands, maybe even configurable via plugin parameters. Just obviously doesn't work for more complex calls that take an object parameter, etc.


People shouldn't want to use your plugin, because it's less to write, but because it does its job better than the rest.
function globalFunction() {


(function(){


//interpreter scope.


}).call($gameMap._interpreter);


}

But I'd prefer if everybody used a namespace instead of filling the global scope with methods that can easily conflict...
I don't think people are going to complain too much about having to write more at this stage or in the future, honestly. Having things break less often would be nice, so my suggestion is the same as Hudell's. Do your own namespace. Don't forget about Plugin Command, tho. You could shorten up script calls that way.
The way I do this is:

class Something {    functioName() {}}module.exports = Something;When Browserify and Babel compile this, Something is no in "global" space it with in the space of the module. To make it global I can do:

window.Something  = Something10/10 times I don't do this unless I know the specific API I am giving you.

As for other things like "monkey patching" core methods they still work using this context.

I don't need people trampling all over my codez with their sticky fingers. So I use models to remove the concept of "global"
The way I did this for my script to keep the script call "qmove()" was to run a regex test of the command first and if there was a match run the real method, and if there wasn't a match call the alias.

Example of what I mean:

https://gist.github.com/quasixi/df5b6065f63b38c25a52

The script call would be

example(args)And it sends the whole args match as a string to the function, which can break the string into an array if needed. 

But there is this bit from the original script call function:

while (this.nextEventCode() === 655) { this._index++; script += this.currentCommand().parameters[0] + '\n'; }that I left out of in my snippet because I'm not sure what event code is 655 to see why / what its doing this for.

Also snippet doesn't replace script calls from set variable or conditional branch.

And the plugin command would be

Example arg1 arg2And args here is sent as an array.

Plugin commands seem a bit weird to me though, not sure if I'm doing it correct either but it runs.
function globalFunction() { (function(){ //interpreter scope. }).call($gameMap._interpreter);}But I'd prefer if everybody used a namespace instead of filling the global scope with methods that can easily conflict...
I would prefer a namespace as well, but I'm still concerned with the prospect of typing more just to make a simple script call.

The way I did this for my script to keep the script call "qmove()" was to run a regex test of the command first and if there was a match run the real method, and if there wasn't a match call the alias.

Example of what I mean:

https://gist.github.com/quasixi/df5b6065f63b38c25a52
Hmm, so intercept the script call itself. I could do that.

But there is this bit from the original script call function:

while (this.nextEventCode() === 655) { this._index++; script += this.currentCommand().parameters[0] + '\n'; }that I left out of in my snippet because I'm not sure what event code is 655 to see why / what its doing this for.
355 is the first line of a script call.

655 are subsequent lines.

And the plugin command would be

Example arg1 arg2And args here is sent as an array.Plugin commands seem a bit weird to me though, not sure if I'm doing it correct either but it runs.
Plugin commands are not always suitable for me because they split on spaces.
Well, you can always join the command parameter with spaces and split them again on your own way. I do so with my Event Popup plugin, which takes a string enclosed in quotes as the last parameter.
Well, you can always join the command parameter with spaces and split them again on your own way. I do so with my Event Popup plugin, which takes a string enclosed in quotes as the last parameter.
True. I could just take something like

my_command 1 formula with spacesWhich would be offered as
Code:
[my_command, 1, formula, with, space]
And then I could just join everything after the first couple fixed parameters and assume everything else is part of the formula.Then evaluate it.

Doing a quoted-string parsing would be annoying though to consider the possibility of escaped quotes and other things.
In my case, i just eval'd the string, because i needed the correct formatting for escape characters, since that string gets passed to Window_Base.drawTextEx. Also i think it's easier for the user, since this way there is a clear boundary for the string parameter they have to provide.
Also i think it's easier for the user, since this way there is a clear boundary for the string parameter they have to provide.
Can you expand on what you mean?
My plugin command takes 2 parameters: The event id where the popup should be displayed and the text (+ an additional parameter to tell the script it should show a popup in the first place). The way it works now, the command looks like this:

EventPopup popup 1 "This is a test text."I think that looks nicer than this:
Code:
EventPopup popup 1 This is a test text.
It's easier to see, where the actual text parameter starts. If the plugin would take a string instead of the number, it would be even more important, since a user could easily confuse that parameter for the start of the actual text.You could even take multiple string parameters if you were to split at quotes not proceeded by backslashes.

Original thread: https://forums.rpgmakerweb.com/threads/alternative-to-defining-functions-in-global-space-for-script-calls.49023/