What array functions are available in RMMV?

I am using arrays to store some data in order to, hopefully, avoid using multiple variables. I was able to get .indexOf to work, but select and fetch aren't working.

For the purpose of this question, I will provide this example.


Code:
//Array of save files that have a save in them (false if empty)
Array1 = [1,1,0,1,0,0]
//Array of data contained on (x) save file
ArraySF1 = [Name:John,cc2,path 1]
ArraySF2 = [Name:Jim,cc1,path2]
ArraySF4 = [Name:Kara,cc4,path1]

Now, I used Array1.indexOf(false) to find the first empty save slot (so I know which save file to save to and can add this playthrough's data to its own array based on that.) this way the third save file is the one the game saves to first using script commands.

What I wanted the select/fetch functions for was to get a list of the indexes in Array1 that return true. (0,1,3) so I can then take that data, compare to the list of other arrays that are made for each save file (1-15) to then grab ArraySF1, ArraySF2, and ArraySF4. I would then check to see if the 2nd index of each of those saves matches a separate variable saved to the current playthrough (something like .value(ArraySF1, [2]) ==Var1?) and build an if statement off of that. Goal would be to narrow the options of save files to load from down to the only viable ones. I just need to figure out how to obtain the indexes of the true values so I can then compare them against my variable list.

Code:
Array1.select(true) = [0,1,3]
//My ArraySF starts at 506, so adding it to the indexes gives the proper variable number
$gameVariables.value(Array1.select(true)+506, [2])
//The above would theoretically give me the second index of the arrays matching those numbers
[1,2,1]
//which I could then check.
set Var2($gameVariables.value(Array1.select(true)+506, [2])==Path)
// which would give a true or false of which ones matched.
Var2 = [true,false,true] // or // [1,0,1]
//where I would then use select to find all of the falses. Which would give first index
set Var3($gameVariables.value(Array1.select(true)[Var2.select(false)]+506,[0])

Which would theoretically let me create choices after doing an if/then for length of the resulting array. So that I could put \V[3,[0]], \V[3,[1]],etc. in the choice boxes and it display the names of actors from the saves on a different path from player. Which, using the above example, would give the name of actor1 from save file 2 and ask the player if they wanted to use that data for their playthrough.
I don't see any documentation describing select() as an array method in JavaScript.

MV supports ES6 so fetch should work, it just isn't in any of the default code since it was originally written using ES5. (note that's also not an array method)

What I wanted the select/fetch functions for was to get a list of the indexes in Array1 that return true.
Code:
let saves=[];
Array1.forEach(element, index => {if (element) saves.push(index);});

That will make saves be an array of the true indices from Array1.
I'm fairly sure all regular JavaScript array functions are available, specifically at(), concat(), copyWithin(), entries(), every(), fill(), filter(), find(), findIndex(), findLast(), findLastIndex(), flat(), flatMap(), forEach(), from(), fromAsync(), includes(), indexOf(), isArray(), join(), keys(), lastIndexOf(), map(), of(), pop(), push(), reduce(), reduceRight(), reverse(), shift(), slice(), some(), sort(), splice(), toLocaleString(), toReversed(), toSorted(), toSpliced(), toString(), unshift(), values(), with().

I recommend Mozilla's tutorials to learn more about them. The ones you mention in your post might have been from another language.

this is the site where I found Select and fetch. It doesn't mention which language it works in.

@Mac15001900 I will definitely give that a look and hopefully I can find more that work in MV

@ATT_Turan where would I put that code? just a general script call in the events?

this is the site where I found Select and fetch. It doesn't mention which language it works in.

@Mac15001900 I will definitely give that a look and hopefully I can find more that work in MV

@ATT_Turan where would I put that code? just a general script call in the events?
Your link says documentation for Ruby. MV uses Javascript
Your link says documentation for Ruby. MV uses Javascript
It mentions javascript in the document and looked like Js to me. but I don't know much of js so there are probably differences I didn't notice.
MV uses JavaScript. fetch and select are Ruby functions, hence why they aren't working for you.

JavaScipt's analog for select is the filter method. There is no equivalent method for fetch, nor is one particularly needed, since you can simply access elements via bracket notation.


It mentions javascript in the document and looked like Js to me. but I don't know much of js so there are probably differences I didn't notice.
The url of the website is ruby-lang.org and the title bar literally says "Documentation for Ruby 2.0.0"
It mentions javascript in the document
...where? Not to beat a dead horse, but I clicked on the link you provided, did a search for "javascript" and got zero hits 😛

where would I put that code? just a general script call in the events?
Wherever you're trying to do it? I don't understand from your first post how you would be doing something in an event that filters the save games shown to a player. It looked like you were trying to write a plugin.
Capture.JPG


It mentions java and i didn't see the url as I only googled for array coding and it looked similar to me.

...where? Not to beat a dead horse, but I clicked on the link you provided, did a search for "javascript" and got zero hits 😛


Wherever you're trying to do it? I don't understand from your first post how you would be doing something in an event that filters the save games shown to a player. It looked like you were trying to write a plugin.
Capture1.JPG

This is my current event. What is currently showing works, and is essentially creating the array of save files in use (Array1) I have the show text events showing the results.

I am not trying to write a plugin as I do not know js and my coding is not the best. I am better at story writing and such. I can certainly do all of this using really long if/then trees but if i can find an easier/less time-consuming way, then even better.
It mentions java and i didn't see the url as I only googled for array coding and it looked similar to me.
Java and JavaScript are two different languages. Also, the sentence you took a picture of only says that arrays are ordered the same way as C-based languages, not that any of the code on the page was for those languages 😉

This is my current event. What is currently showing works, and is essentially creating the array of save files in use (Array1) I have the show text events showing the results.
Okay...this is a kind of convoluted way to go about this. You're basically rewriting a version of the load screen using events?

You can just put this in a Script box:
Code:
let globalInfo = DataManager.loadGlobalInfo();
$gameVariables.setValue(505, []);
globalInfo.forEach(file, index => {if (index>0 && DataManager.isThisGameFile(index)) $gameVariables.value(505).push(index);});
That should make variable 505 be an array of valid save file IDs. You don't need that whole page of other variables.

I do not know js and my coding is not the best.
It might save time to just ask first next time 😉 Guessing with computer code has a nearly 0% chance of success.

Let us know if you have any problems using the above.
Java and JavaScript are two different languages. Also, the sentence you took a picture of only says that arrays are ordered the same way as C-based languages, not that any of the code on the page was for those languages 😉


Okay...this is a kind of convoluted way to go about this. You're basically rewriting a version of the load screen using events?

You can just put this in a Script box:
Code:
let globalInfo = DataManager.loadGlobalInfo();
$gameVariables.setValue(505, []);
globalInfo.forEach(file, index => {if (index>0 && DataManager.isThisGameFile(index)) $gameVariables.value(505).push(index);});
That should make variable 505 be an array of valid save file IDs. You don't need that whole page of other variables.


It might save time to just ask first next time 😉 Guessing with computer code has a nearly 0% chance of success.

Let us know if you have any problems using the above.
Wait. Can i use globalInfo to get info from saves? like actor1 name from save2??
What I am going for is kinda like a new game+ but the plugins I found didn't do what I wanted which is to narrow down which saves can be newgamed from depending on the path chosen in those saves. I will go plug in the code you gave me to test it now.
Wait. Can i use globalInfo to get info from saves? like actor1 name from save2??
What I am going for is kinda like a new game+ but the plugins I found didn't do what I wanted which is to narrow down which saves can be newgamed from depending on the path chosen in those saves. I will go plug in the code you gave me to test it now.
Didn't you ask this yesterday in a separate thread? And wouldn't it be easier to do something like copy that save file, reset a bunch of switches and variables and send the player to the starting map?
You can just put this in a Script box:
Code:
let globalInfo = DataManager.loadGlobalInfo();
$gameVariables.setValue(505, []);
globalInfo.forEach(file, index => {if (index>0 && DataManager.isThisGameFile(index)) $gameVariables.value(505).push(index);});
That should make variable 505 be an array of valid save file IDs. You don't need that whole page of other variables.

Alright I put this code in and it says 'file not defined' file is just... each index of globalinfo, yes? or am i mistaken?
Didn't you ask this yesterday in a separate thread? And wouldn't it be easier to do something like copy that save file, reset a bunch of switches and variables and send the player to the starting map?
yes and general consensus was i had to use persisting variables and what not. I was reasking this particular question because would be easier to just globalinfo save1 actor1 name than to still have to use the persisting variables to get everything saved.
Alright I put this code in and it says 'file not defined' file is just... each index of globalinfo, yes? or am i mistaken?
You're mistaken. But I guess it doesn't like it because there is no element 0.

So try it in a loop instead.
Code:
let globalInfo = DataManager.loadGlobalInfo();
$gameVariables.setValue(505, []);
for (let i=1; i<globalInfo.length; i++)
{
    if (DataManager.isThisGameFile(i))
        $gameVariables.value(505).push(i);
}

It definitely would've caused less confusion for this to all be in your original thread so everyone can see what you're trying to achieve and what had already been told to you.
You're mistaken. But I guess it doesn't like it because there is no element 0.

So try it in a loop instead.
Code:
let globalInfo = DataManager.loadGlobalInfo();
$gameVariables.setValue(505, []);
for (let i=1; i<globalInfo.length; i++)
{
    if (DataManager.isThisGameFile(i))
        $gameVariables.value(505).push(i);
}

It definitely would've caused less confusion for this to all be in your original thread so everyone can see what you're trying to achieve and what had already been told to you.
my original thread was a different question entirely, so i didn't think the new question would fit there. The code worked this time so that at least removes the need for a filter function to get all open saves. Thanks for that.

Should I have more questions, should I just add them into this thread? regardless of similarity in topic?
Should I have more questions, should I just add them into this thread? regardless of similarity in topic?
...no, make separate threads for separate topics, but I don't see how this is a different question entirely.

Your first thread said:
If I wanted to get the name of a certain actor in file2 and set it as a variable in file3, how would I do that? I know there are new game+ plugins but I need to be able to filter which saves are being accessed for the new play-through so they don't work for what I am trying to do.

Then when you got to it in post #11 of this thread:
What I am going for is kinda like a new game+ but the plugins I found didn't do what I wanted which is to narrow down which saves can be newgamed from depending on the path chosen in those saves.

To me, that reads as the same question.
...no, make separate threads for separate topics, but I don't see how this is a different question entirely.

Your first thread said:


Then when you got to it in post #11 of this thread:


To me, that reads as the same question.
the question was reasked in regards to using the globalinfo for this current problem and me wondering if it would fix my other problem. these were two different questions. One asking if I can locally get save data from other saves, another asking what array functions were available in RMMV since I needed something like select or fetch because I wanted to get a list of variables from my arrays.
My apologies for the confusion, won't happen again.
Okay...then I guess I just still don't understand what the event is for.

Glad you got some working code, good luck with your project.

Original thread: https://forums.rpgmakerweb.com/threads/what-array-functions-are-available-in-rmmv.163018/