MV Why does $gameVariables.value(x) break my plugin

I made a plugin that generates a bunch of (1152) characters with a bunch of stats, using a ton of formula's.

This works great, and does exactly what I wanted it to do.

Hoever, if I want to call for the 1st character, and I do this, it works and I get the 1st character of the 1st team:
Code:
arrCharacters[1][1];
(Note that each array starts with a NULL, so there is no team 0 or player zero)

However, as soon as I do this, the plugin does nothing:
Code:
arrCharacters[1][$gameVariables.value(x)];

If I use gameVariables anywhere in my the plugin, it just stops working. Even when I just do this:
Code:
var X = $gameVariables.value(1);

When the plugin stops working, it actually does nothing, as if it isn't even installed.

Does anyone know why this happens? I know it is kind-of hard without looking into my plugin, but hopefully this is something someone recognizes. I would share the problem part, if I knew which part is the problem.

I will be able to make the game with the plugin as it is, but with the use of Variables, it would be a lot easier.
When asking about coding problems it's generally a good idea to include error information. You can find this in the DevTools (Press F12)
JavaScript is a case sensitive language. This means that foobar is different from fooBar and fOobaR
Given this knowledge can you spot a problem in your code snippets?
However, as soon as I do this, the plugin does nothing:
Code:
arrCharacters[1][$gameVariables.value(x)];
just to doublecheck, you are assigning a value to that game variable first right? and you can confirm that the value ingame? $gameVariables.value() returns a 0 if the variable is undefined, so if you havent assigned anything to it, it will get you the null player

If I use gameVariables anywhere in my the plugin, it just stops working. Even when I just do this:
Code:
var X = $gamevariables.value(1);
the v in variables there is to be uppercase
If a plugin stops working as if it isn't even installed, usually it's because there's a typo in your code that prevents it from being parsed. Or something else that prevents the definitions of the functions, like conditional definitions (if x == 1 then function = blah). Do the functions even get defined properly?
Looks like an excellent opportunity to learn about the debugger. In the game, before the error happens, press F8/F12 to open debug console, go to "Source" and go to the line of code that you want to inspect. Click on the left of a line to enable a break point. When you continue playing your game, it will pause when you reach this point and you can inspect all the variables
When asking about coding problems it's generally a good idea to include error information. You can find this in the DevTools (Press F12)
JavaScript is a case sensitive language. This means that foobar is different from fooBar and fOobaR
Given this knowledge can you spot a problem in your code snippets?
I know so much about javascript, I don't even know what a snippit is. I'm going to google that in a minute.

The lover case v is a typo in the post, not in the code. Typo's is the first thing I check when things go wrong. 😛

just to doublecheck, you are assigning a value to that game variable first right? and you can confirm that the value ingame? $gameVariables.value() returns a 0 if the variable is undefined, so if you havent assigned anything to it, it will get you the null player


the v in variables there is to be uppercase
Oh the lowercase is a typo in the post. Not in the code. I even copy-pasted it from a working script just to make sure there wouldn't be a type.

And yes, the game variable I try to call for is set to 1, and should give the same result as when I just type [1].

If a plugin stops working as if it isn't even installed, usually it's because there's a typo in your code that prevents it from being parsed. Or something else that prevents the definitions of the functions, like conditional definitions (if x == 1 then function = blah). Do the functions even get defined properly?
Well, the plugin works, if I say 1 instead of $gameVariables.value(). And checked if there is a type in there many times.

I don't know what you mean by the plugin getting defined? Yeah, I try to do this with minimal javascript knowledge. 😛 I'll try to look that up as well.


Looks like an excellent opportunity to learn about the debugger. In the game, before the error happens, press F8/F12 to open debug console, go to "Source" and go to the line of code that you want to inspect. Click on the left of a line to enable a break point. When you continue playing your game, it will pause when you reach this point and you can inspect all the variables
I tried F* a lot, but half of what I see I understand. It is nice when it guides me directly to the line in my code that is wrong, but here, there is no error so it won't do that. 😛



@All I wonder if I should share the full code in order for you to be able to help me. I hope that isn't needed, because it would reveal everything. And I am not scared it is so good people will steal it, but it would spoil the magic... If I give everyone a peek behind the curtain, the actual game wouldn't impress that much.

Slso, my future players might see and winning would be too much easier if you know how the AI is programmed. 😛 (I learned that the hard way, with my card games. Everyone who got a peek, suddenly was able to defeat the game 9 out of 10 times.)

Thanks for trying to help though! It is really appreciated. I just wish I could be more clear about the problem, but I don't know it myself. 😛

I'm going to google some of your suggestions and work with them. I'll keep you updated. Oh and I'll correct the typo in the post. This typo is 100% surely not present in the code. I tried it once more, just to be sure. (But I tried it already in different stages of creating the plugin, and it never worked.)

Edit: Omg, I even saw the typo when I made the original post, clicked edit and corrected it, but then I went to bed without clicking the save button... 😛
Play around with the dev tools and break point as Aerosys mentions. You can go through your code step-by-step. At each step you can inspect the contents of the various variables.
A debugger is such a useful tool. It help you soo much as a programmer.
Spoiler: Old stuff. Read unspoilered update instead.
Play around with the dev tools and break point as Aerosys mentions. You can go through your code step-by-step. At each step you can inspect the contents of the various variables.
A debugger is such a useful tool. It help you soo much as a programmer.
Yeah, I am trying to figure out what it does. I mean, I can see my code... But I can't seem to figure out the break points.

However, I do check the variables used like this:
1721401756940.png


So I do see that var 39 and 40, which the code tries to read, are set to one. And it freezes. But when I replace the "$gameVariables.value(x)" and with an actual 1, it works.

I'll play around with the debugger a bit more. If I can't find the problem, I might rewrite the plugin step by step, with a variable in there from the beginning, to see where exactly it stops working.

FIXED!!!
So, what I did is, I copied the plugin over into a new file, line by line. The only difference is that I had this part in the code at all times, and I tested it after each piece of code I copied over, expecting it to fail at any moment... But it never did.
JavaScript:
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);

        if(command === 'Test') {
            $gameVariables.setValue(2, 'If you can see this, the common event works.');
            alert($gameVariables.value(2));
        }
    };

I have no idea why it failed in 1 plugin, and works just fine in the other, since I changed nothing other than adding the plugin command.
Might be solved already, but guessing from your change... Maybe you were running the function at start, like in a IIFE, before the initial arrays are loaded.

Was it similar to this?

(function() {
function stuff ()
{
}
$gameVariables.value(x);


stuff();
}());
Might be solved already, but guessing from your change... Maybe you were running the function at start, like in a IIFE, before the initial arrays are loaded.

Was it similar to this?

(function() {
function stuff ()
{
}
$gameVariables.value(x);


stuff();
}());
Well, it started with "function()" at least. 😛

I don't really know, but it works now. So, I don't want to waste any energy on guessing what went wrong. 😛

The game this was for, is going like a train, though. It grows so freaking hard.
I don't know if it's the same problem, but I once spent hours trying to figure out why a SCRIPT I wrote in another language didn't return an error, so I copied the entire code to a new notepad and changed the encoding.
Enconding.png
I use visual studio code. This software indeed can use different languages, but the only difference is how the text is displayed on the screen.

It has something that looks like a spell checker, which is great for debugging. And the text is color coded. Those are the only things that change when selecting another language. The file itself doesn't change.
I'm pretty sure the encoding is set per file and not by the software, and that all advanced editors have the option to switch between ANSI, UTF-8, and UTF-8 without BOM:
1722439030138.png


And just explain that I had a problem similar to yours, but it was when compiling a script.
Even changing the editor SOFTWARE did not work because there was some character that was not accepted and the file was in ANSI, but it was probably hidden and close to some line break.
Oh... I think I misunderstood. I though it was the setting where I set it to javascript.

I don't really know what encoding it. 😛 It is too much to learn all at once, though.
mine is always "UTF-8" some files "UTF-8 with BOM" whatever that means
both with CRLF so once it's on UTF-8 you should be good. as that is the standard
setting for me, if it's not on your end in VSCode, than you can do that in the settings.
Then maybe that was wrong in the first plugin. It works now though.

Original thread: https://forums.rpgmakerweb.com/threads/why-does-gamevariables-value-x-break-my-plugin.170431/