Having an issue with pulling several strings from an array.

Hello all, I previously got help here with pulling a random string from an array and it went well. The thing is, I need to do the same thing a few times in a row, and when I try to do it even with replicating the code perfectly, it won't work.

Here is the code that works.

var pool = ["A", "E", "I", "Y", "U"];

$gameVariables.setValue(20,pool[Math.floor(Math.random() * pool.Length)])
​
Pretty straightforward, works like a charm. The thing is, when I copy that exact code but just change it a little, for instance to this


var pool = ["A", "E", "I", "Y", "U"];

var pill = ["B", "J", "S", "M", "W"];

$gameVariables.setValue(20, pool[Math.floor(Math.random() * pool.length)]);

$gameVariables.setValue(21, pill[Math.floor(Math.random() * pill.length)]);
​
And then I try to display whatever is in both variables

\V[20] \V[21]
​
I only get a random result from the first variable, then a ZERO for the second one. Can anyone shed some light into why this is happening? Would it be easier if I just made a big external text file with all the text in it and pulled from that somehow?
I don't see anything wrong with what you've got there. So I'm thinking maybe you've made a typo in your code, that you didn't reproduce when retyping everything here.

You can see how typos are possible because in your "code that works" you have made a typo, and if you had that exact command in your script call, it actually wouldn't work at all.

Can you please provide a screenshot so we can see your exact commands?
Also confirm you're not using variable 21 anywhere else.
jzABISU

That's the code exactly
jzABISU.png


8mAKPTC

That's what happens when i run it. That is a zero, there's no letter O in the second array.
8mAKPTC.png
Did you check to see if you're using variable 21 anywhere else? You can use the Variable Search tool in the toolbar, but it will not search through script calls or plugins. So also check all of your plugins and see if any of those are using variable 21.

If you still can't find it, change your script call to be this, and play with the console open (F8, Console tab). See what it prints out to the console at each stage.

Code:
var pool = ["A", "E", "I", "Y", "U"];
console.log(pool);
console.log(pool.length);
var pill = ["B", "J", "S", "M", "W"];
console.log(pill);
console.log(pill.length);
$gameVariables.setValue(20, pool[Math.floor(Math.random() * pool.length)]);
$gameVariables.setValue(21, pill[Math.floor(Math.random() * pill.length)]);
console.log($gameVariables.value(20));
console.log($gameVariables.value(21));

Please post a screenshot of your console after running this.
Also check your max variable ID in the editor, e.g. Control Variables > (select a variable) > Change Maximum.

Attempting to get or set the value of a variable whose ID is over the editor maximum will result in a failure, and the default "failed" value is 0.
Oh good lord, I had forgotten to make more than the standard 20 variables on this project. I slapped my forehead so hard there's now a handprint there, thank you all for your time. I guess I could segue this into asking how ot pull these strings from an external text file but I should probably make a newe thread about that. Thank you all again!

Original thread: https://forums.rpgmakerweb.com/threads/having-an-issue-with-pulling-several-strings-from-an-array.115819/