Storing game state, and importing js libraries [scripting]

Hi all,

I'm new to RPG maker, but it looks like I joined the train at the right time - JS scripting is something I'm more familiar with than Ruby. However, there are some things I haven't been able to figure out by looking through the docs:

1) Is there a central place to store arbitrary game state into the engine database?

For example, let's say I want to store a session ID after connecting to a multiplayer game server, where would I store this? How would it be accessed? Can something in the database be accessed anywhere within the engine?

2) Is it possible to import arbitrary JS libraries that I create, that can be used within all parts of the game?

Let's say I want to create a library that executes an HTTP request and do something with the results (like storing a session ID into the database), and I want this to be executed on certain map events. How would I include this library to be accessible to all events?

This is for RPG Maker MV of course.

Thanks!
I've moved this thread to JS/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
1. I'd say, just store it in a global variable you can easily identify. For example, for a script I'm working on, TriNameGen, I store all data for my name generator in CXJ.TriNameGen.Library.

2. Personally I would put all libraries in /js/libs, add a script link to it in index.html, and then create a plugin that would hook all library commands to either plugin commands, or directly use the methods in the script event. I myself would decide which to use based on situation, for some things, plugin commands are simpler, but script events are more flexible.

An alternative way to load in scripts is to add the script through the DOM instead of adding lines to index.html, and then execute the plugin through the onLoad event. This has the advantage of it being easy for others to implement themselves, as they don't have to mess with index.html. That is, if you're going to publicly release it.
1. The "database" is stored in the JSON files produced by the editor, it's not a "place" where you can store arbitrary variables at runtime. If you're writing a plugin and you use the immediately-invoked function expression (IIFE) convention, you can declare a normal variable inside it and rely on the closure scope, assuming everything that needs to access that variable is also within it. Otherwise, like GaryCXJk alluded to, you can expose a global object called $myPluginName or whatever, and define it as a property on that. Or if there's already a suitable object provided by the engine where it would make sense to store it, add it to that (but you have to be careful when doing this to prevent overwriting anything or potential naming conflicts with other scripts).
Excellent! I will try these recommendations.

Thanks,

Original thread: https://forums.rpgmakerweb.com/threads/storing-game-state-and-importing-js-libraries-scripting.49096/