Assigning a user defined GameVariable & using its value in javascript

So simply put I have things set up as follows


@params: VariableToBeReferenced


@desc


@default: 5


I am using the following... though I've been uncertain about it.


var params=PluginManager.parameters('MyPlugin')
var VarNumber = Number(params['VariableToBeReferenced'] || 5);
var VarValue = return $gameVariables.value(VarNumber);


VarValue is used later as part of
return this.allMembers().slice(4, VarValue)
};


Placed simply I am making a window that shows only reserved party members up to a specific point in this example. Everything worked fine until I added VarValue into the situation. I've tried a few variations but figure I've just overlooked something and been fundamentally wrong in how I've applied it from the beginning.


If I replaced VarValue with VarNumber it will give me the actors in index 4-5 by default and nothing more so in concept it works fine. The problem is how I'm assigning the value to the game variable. Help this noob out please.
get rid of VarValue altogether, and change the later part to 


return this.allMembers().slice(4, $gameVariables.value(VarNumber))


Reason is your params are read and VarNumber and VarValue are allocated values when the game itself is launched, and at that time, all variables are 0 (so VarValue will be set to 0).  Then you either start a new game (which resets the variables to 0 again) and play, and at some point the variable will be changed, but VarValue will not be changed, or you will resume a saved game and the variable will have a non-zero value, but VarValue will still be 0.


var VarValue = return $gameVariables.value(VarNumber) does not mean "whenever I use the variable VarValue, go and see what is in that game variable and give it back to me".  It means "go and see what is in that variable RIGHT NOW, and set VarValue to that until I change it again - which I'm not going to do"
I see. Thank you once again Shaz for your timely explanation. I appreciate it.

Original thread: https://forums.rpgmakerweb.com/threads/assigning-a-user-defined-gamevariable-using-its-value-in-javascript.69811/