You're checking to see if the jokes are all done before splicing one out, the numbers you're stating all seem to match up, and the script calls look OK. I'm not sure why it would skip one of them. Is it always the same one that gets skipped?
Like Turan says, the
new Array(140) command should be removed. It does generate the wrong range of values (1~140 instead of 1801~1904), but that's irrelevant because you exit the event right afterwards. It's just unnecessary.
Oh. That's what I get for trying to keep track of too many threads at once!
😴
I did a quick search and didn't find an MV version of triacontane's plugin. It should be pretty simple, though.
Spoiler: plugin and walkthrough
Try saving this as a .js file, then import as a plugin:
JavaScript:
/*:
* @target MV MZ
* @plugindesc Load custom JSONs into global vars, for access via script call.
* @author Caethyril
* @url https://forums.rpgmakerweb.com/threads/163256/
* @help Edit the plugin code to customise variable & file name pairs.
*
* Free to use and/or modify for any project, no credit required.
*/
DataManager._databaseFiles.push(
// Load Stuff.json into $dataStuff on game boot
{ name: "$dataStuff", src: "Stuff.json" }
);
As noted in the plugin help, you can rename it to
$dataJokes and
Jokes.json or whatever you like by editing the code.
Then if the JSON file looks like this (save it as a .json file in your project's data folder):
JSON:
[
"Index 0",
"Index 1",
"Index 2"
]
You should be able to access it in-game like this:
JavaScript:
$dataStuff[0] // "Index 0"
You would still need an array to splice out of, though, because
$dataStuff should remain constant during play. So, something like this:
- Control Variables 1498 -> Script (based on length of
$dataStuff):
JavaScript:
Array.from($dataStuff, function(_, n) { return n; })
This gets a list of array indices for each entry of $dataStuff. Checking for "all jokes done" will work the same as before.
- Splice out of variable 1498 just like before, into variable 1499.
- Get joke text for selected index:
JavaScript:
$dataStuff[$gameVariables.value(1499)]
If you don't care about keeping hold of the joke index at this point then you could just store this text in variable 1499 (i.e. replace the joke index number with the respective text). Otherwise you'd want to store it in a third variable (1500?) so you can display it via the \v text code.
It's a test message: it shows the selected joke ID (value of var 1499), followed by the respective joke's text (value of var with ID equal to value of var 1499).
So I re-ran the full test on all the jokes, and confirmed that all of the jokes do get represented with the event as presently written.
Here's a souvenir image of the two full test results because they took so long they deserve to be memorialized SOMEWHERE
I completely misunderstood what
new Array(140) did, I understand better now. This is my first time working with arrays, it will be a continuing education I'm sure.
@caethyril your plugin works perfectly, I just have two quick questions, since I'll be porting over the (actual thousands of) static strings from vars to this database.
First, I'm a little unclear where I would plug in the number of entries here:
Control Variables 1498 -> Script (based on length of
$dataStuff):
Array.from($dataStuff, function(_, n) { return n; })
Let's say I have 134 entries here, which I do in the current case -- what would that script look like in that case?
My other question has to do with how I would manage one of these little DB's in a case where the entries get cycled through in order, which is another use case relevant to my project. In that case, I have hundreds of text strings that would get called in order, rather than the trickier random-and-remove-from-array situation.
Thanks again for bearing with me, this is so enormously useful I am honestly kind of speechless. Thank you so much caeth for this little plugin too, I can't believe you can get so much functionality from such a tiny little piece of javascript. Kind of incredible imo.
-c