MZ Define functions to be called through script calls or script command events

I'm trying to define functions considering three main requirements:
  • Be able to call them through script (for ex: author.myPlugin.sayHello(); )
  • Be able to use the Script Command event from the UI
As an extra:
  • Have the function be defined like this so that VSCode actually shows me it's a function and shows me the JSDoc when I hover over it:
    JavaScript:
    function sayHello() {}
    Yes, I'm a maniac regarding tidyness and documenting.

I've tried several methods and searched around but was completely unsuccessful. Either I'm unable to use Script Command event or unable to call the function through script, I can do each of them just not at the same time so I'm wondering if I have to even define my plugin in a certain particular way to allow for this.
It would help if you showed what you had tried to do, because it's impossible to just guess what's wrong.

The function definition you show there will work perfectly well in a Script command (provided it actually does something).

1708098597636.png


1708098619162.png


1708098650524.png
You can define and call it directly from the script command or define it in a plugin file, add it to your project, then call it from the script command.
I tried so much stuff I could turn it into a guide on what not to do, so I guessed it was easier to ask for the proper way lol

Here's what I'm currently doing though

I modified it to try what you suggested

1708101017398.png
.

When I just try the script function call, it works properly
1708101612284.png

1708101585401.png
.

Yet when I try using the Plugin Command event, it doesn't
1708101438405.png
.
1708100828058.png
.


EDIT: I want to be able to use both ways to call the same function for flexibility since sometimes it can get messy or impossible to make some stuff using events but RPGMMZ is not really a comfortable platform to use scripting as the main way to code

I'm trying to make a plugin for personal use so that I can be more comfortable while using the engine
Edit: Just having an off day, nothing to see here... 😮‍💨
Your screenshots contradict:
  • In the code, you have registered the command for stell.js (because PLUGIN_NAME = 'stell').
  • In the event, you are referencing a plugin named Stellcode.js.
You need to register the command under the plugin's filename (case-sensitive).

Also, to clarify, $gameVariables.setValue(id, value) is absolutely OK with values of any type. Incoming values of type number will be floored; other values will be assigned as-is. Assigning a falsy value to a variable will cause that variable to return 0 via $gameVariables.value.
Thanks for the correction...I missed the name conflict and didn't look at the function before spouting off 😛
Your screenshots contradict:
  • In the code, you have registered the command for stell.js (because PLUGIN_NAME = 'stell').
  • In the event, you are referencing a plugin named Stellcode.js.
You need to register the command under the plugin's filename (case-sensitive).

Also, to clarify, $gameVariables.setValue(id, value) is absolutely OK with values of any type. Incoming values of type number will be floored; other values will be assigned as-is. Assigning a falsy value to a variable will cause that variable to return 0 via $gameVariables.value.
Yay, that was it!
I didn't know that part, thanks a bunch!
So everything I tried before wasn't wrong then, the plugin name was the problem heh, nice catch!

Thanks to the both of you for your time!

Original thread: https://forums.rpgmakerweb.com/threads/define-functions-to-be-called-through-script-calls-or-script-command-events.165823/