Randomness in npc dialogue script help

I have been trying to add variety to my NPC dialogue using the following RPG Maker MZ Tutorial:

Random NPC Dialogue - the 4th method "Use script calls to simplify random dialogue removal"

I have copied the event and script from the tutorial line by line.

In my game, the NPC returns the number 4 in the text box so I redid everything and it still does the same.

To test the script I started a new blank project and created an NPC for the player to talk to, in this clean "build" I do not get the number 4, but the error:

TypeError
$gameVariables.value(...).splice is not a function

Which is equally baffling as in my game build I get a random number thrown back at me.

Here are my Events:

EventPage1.png


EventPage2.png


And I have variable 5 set up as:

Variable5.png


Is there something I am doing wrong?
Before the splice line can you add

console.log($gameVariables.value(5))

and see what the console outputs?
Before the splice line can you add

console.log($gameVariables.value(5))

and see what the console outputs?

Thanks for the help, I have done this, does this create an output file somewhere?
Thanks for the help, I have done this, does this create an output file somewhere?
Press F8 and click to the Console tab.
This is what pops up when it errors.

Console.png
So you can see from the console log there that at the time this code is running, the variable contains the value 17.

Have you used variable 5 for another thing in this project?
So you can see from the console log there that at the time this code is running, the variable contains the value 17.

Have you used variable 5 for another thing in this project?

No, this is the test project, created just to try and get the script to work.

Strange, will start it again!
So I started a brand new build, and this time it works like a charm. Now I know it works clean,
previous Random results must be contaminating my actual Game Build, that may explain the "4" result I am getting.

Thank you.

UPDATE: You guys cracked it thanks. I was using a previously used Random variable, new variable used, no more issues.
A question about random variable values: if I put as the reference values "0" and "100", is 0 an actual possibility, so in total the randomly generated values are 100 + 0, for a total of 101?
A question about random variable values: if I put as the reference values "0" and "100", is 0 an actual possibility, so in total the randomly generated values are 100 + 0, for a total of 101?
Yes, the range will include both numbers you enter in the input boxes.
Well I've minimally done this wrong then.

So if I want an event with 75% of one output and 25% of another the values I'd aim for are 1-100 not 0-100?
Well I've minimally done this wrong then.

So if I want an event with 75% of one output and 25% of another the values I'd aim for are 1-100 not 0-100?
0-99 or 1-100, yes.

Original thread: https://forums.rpgmakerweb.com/threads/randomness-in-npc-dialogue-script-help.151802/