Storing game state, and importing js libraries [scripting]

Kiboto

Villager
Member
Joined
Nov 1, 2015
Messages
9
Reaction score
0
First Language
English
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!
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've moved this thread to JS/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
 

GaryCXJk

Veteran
Veteran
Joined
Dec 24, 2012
Messages
88
Reaction score
46
First Language
Dutch
Primarily Uses
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.
 
Last edited by a moderator:

NoInkling

Veteran
Veteran
Joined
Oct 2, 2015
Messages
39
Reaction score
10
First Language
English
Primarily Uses
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).
 
Last edited by a moderator:

Kiboto

Villager
Member
Joined
Nov 1, 2015
Messages
9
Reaction score
0
First Language
English
Excellent! I will try these recommendations.

Thanks,
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top