MZ What's the point of plugins if I can't access data?

Hi.

I'm trying to create a plugin. Part of it is an array that contains important data for the game. I cannot seem to create script calls in events that allow me to access that array. I'm aware that's because the data in the script is not global. I can do plugin commands to run specific functions - but I guess I just can't access any data in the script even using other scripts in events? Do I have to assign the array to a $gameVariable.value(), converting it to a useless string, then convert it back? What's the point?
Huh? In MZ, anything you declare inside a plugin is inside the plugin’s private scope, so event Script Calls can’t see it. To access plugin data from events, you have to put that data on a global object.
In MZ, anything you declare inside a plugin is inside the plugin’s private scope, so event Script Calls can’t see it. To access plugin data from events, you have to put that data on a global object.
just to note, this is true if your plugin runs within an IIFE. without one, a variable declared outside of a function's scope would be global.

I cannot seem to create script calls in events that allow me to access that array.
you would have to show exactly what youve done for anyone to say much else.
Do I have to assign the array to a $gameVariable.value(), converting it to a useless string, then convert it back? What's the point?
setValue allows you to assign arrays without needing to stringify them, and the assignment is by reference. so anything you'd to to it would happen to the original array and there'd be no need to "convert back". but if the variable was already in global scope there's no need to outside of saving the value to the save file vs letting it reset with the session
just to note, this is true if your plugin runs within an IIFE. without one, a variable declared outside of a function scope's would be global.


you would have to show exactly what youve done for anyone to say much else.

setValue allows you to assign arrays without needing to stringify them, and the assignment is by reference. so anything you'd to to it would happen to the original array and there'd be no need to "convert back". but if the variable was already in global scope there's no need to outside of saving the value to the save file vs letting it reset with the session
For some reason it seems even if I save arrays into these variables -- I still cannot access objects by index nor their properties.
For some reason it seems even if I save arrays into these variables -- I still cannot access objects by index nor their properties.

If you set the array elements values to game Variables, you still will be able to access only the game variables. Your messages are so vague at the moment that it is impossible to help you. You need to be more direct with what you're trying to do, and what you have done already.
If you set the array elements values to game Variables, you still will be able to access only the game variables. Your messages are so vague at the moment that it is impossible to help you. You need to be more direct with what you're trying to do, and what you have done already.
Right. So say I have a list of characters with stats. The best way to store that is in an array containing objects, yes? So - say I save that array into a $gameVariables(x) let's just call it "x". That "x" should contain the array, yes? Okay. Now say I want to access a property of one of the objects of the array. Say it's the "name". And let's say I want that to be determined by another $gameVariables(y). If I make a script that's meant to say set an event name like $gameMap.event(z).event().name = $gameVariables(x)[$gameVariables(y)].name;

It won't work.

Nor if I do JSON.stringify on it.
It won't work.
this is exactly why I said:
you would have to show exactly what youve done for anyone to say much else.
because your script calls arent correct

say I save that array into a $gameVariables(x) let's just call it "x". That "x" should contain the array, yes?
variable x should be your array, yes. when setting it, the script call to do so is $gameVariables.setValue(x, value) where value is your array. the script call to retrieve the value is $gameVariables.value(x), not $gameVariables(x). you should have gotten an error in the console when using that for it not being a function

this is a list of script calls you can use with the base engine thats pinned in the support sections. it has examples for using them.

additionally...
The best way to store that is in an array containing objects, yes?
$gameActors is an object that already contains the information for all your actors, and $dataActors is an array has the database information for them. if the characters youre trying to draw from are actors, then theres no strict need to put them into a separate array. You could draw from either one of them depending on what you need.

I've moved this thread to Javascript/Plugin Support. Thank you.

this is exactly why I said:

because your script calls arent correct


variable x should be your array, yes. when setting it, the script call to do so is $gameVariables.setValue(x, value) where value is your array. the script call to retrieve the value is $gameVariables.value(x), not $gameVariables(x). you should have gotten an error in the console when using that for it not being a function

this is a list of script calls you can use with the base engine thats pinned in the support sections. it has examples for using them.

additionally...

$gameActors is an object that already contains the information for all your actors, and $dataActors is an array has the database information for them. if the characters youre trying to draw from are actors, then theres no strict need to put them into a separate array. You could draw from either one of them depending on what you need.

Moved to: Javascript/Plugin Support
I already know literally everything you just said. I was explaining using an example. Either way - it started working now. I don't know exactly what it is but that's how it goes with RPG Maker.
I already know literally everything you just said. I was explaining using an example. Either way - it started working now. I don't know exactly what it is but that's how it goes with RPG Maker.
No, it's not RPG Maker, that's programming.

In a game, you have more than a simple database where you can SQL-query everything. You have different kind of data:

- Data that loads on game start and lives forever (e.g. BGM volume)
- Data from your disk, e.g. maps, items, skills, classes, initial skills of actors, ...
- Data that lives while on a map, e.g. where your player is, where the events are, how they look like right now...
- Data that lives in your save game, and resets when starting a new game, or loading another save, e.g. switches, variables, selfswitches, members of your party, the levels of your actors...
- ...probably some more

From reading your posts, it looks like you're mixing them up. But it would help us a lot when you would provide a biiiit more information.

Original thread: https://forums.rpgmakerweb.com/threads/whats-the-point-of-plugins-if-i-cant-access-data.182138/