MV Array functions don't function outside of the console

Hi!~ I'm new to the forum as I've just gotten a copy of RPGM MV. I skimmed the rules a bit so please tell me if this violates the rules, but I've got some JS trouble.

I have a variable storing a list of possible skills you can learn in the game, and if I use, for instance:

Code:
$gameVariables.value(55).indexOf("Fire")

To search for the index of Fire in that list, then it returns 1 like normal.

1601327794926.png


However, directly above it you can see that it's telling me that .indexOf is not a function when executed as a script by one of my game events. This equivalent happens whether I use .contains, .includes, or .indexOf

The script below is the one in question, which sets up [0057] to be an array containing moves that the player knows from the database [0055].

Code:
var skillArray = new Array();
$gameVariables.setValue(57,skillArray);

$dataSkills.forEach (
  function (skill) {
    if (skill) {
      if ($gameVariables.value(55).indexOf($dataSkills[skill.id].name))
        skillArray.push($dataSkills[skill.id].name);
        $gameVariables.setValue(57, skillArray);
}})

Any idea what this could be? :oswt2:
Hi!
The error is happening because it seems that databaseArray is not an array, so it cannot execute the indexOf function.

Besides that, I can't know for sure your context, but it seems to get compatibility problems with the plugins:
Yep Hit Acuracy, Srd Camera Core and Yep Core engine.

But also I think the problem can be here(I mean, I have seen a lot of problems, but maybe you can fix these ones and post the results first):
$dataSkills[skill.id].name
try to replace for this:
$dataSkills[id].name

But the best you way you can debug is using console.log to see what is going on.

JavaScript:
var skillArray = new Array();
$gameVariables.setValue(57,skillArray);
console.log($gameVariables.value(57))
$dataSkills.forEach (
  function (skill) {
    if (skill) {
        console.log($gameVariables.value(55)
      if ($gameVariables.value(55).indexOf($dataSkills[skill.id].name))
        skillArray.push($dataSkills[skill.id].name);
        $gameVariables.setValue(57, skillArray);
}})

Original thread: https://forums.rpgmakerweb.com/threads/array-functions-dont-function-outside-of-the-console.128029/