MV Arrays and Splicing Results

Hello!

So I’ve seen how to roll a value from an array, and I get that I can remove a value from that same array using a splice.

My question is: Once I’m done using that script (I plan on putting it as a common event so I can repeat it over and over again)

How would I script it to reset the complete values without the ones that are taken?

Not sure if I’m making sense so:

if the array is 1-10, I trigger the common event, a random value is taken away, I run the common event again and another value is taken away, now I trigger another event and it reset the values back to 1-10.
I think, in this case, I would copy the list for each run like this:

Code:
var list = [10, 20, 30, 40, 50, 60, 70, 80];
var numberToExtract = 20;
var listWithoutSomeElement = list.filter(item => item != 20);

// list still contains all numbers, while listWithoutSomeElement lacks of the 20
if the array is 1-10, I trigger the common event, a random value is taken away, I run the common event again and another value is taken away, now I trigger another event and it reset the values back to 1-10.
by default, itll reset those values every time if you only did it through script. you might have to save your array as a gameVariable so that it can persist between runs of the common event, and then save the data of the current event as another variable. with that, i believe you can have a check within the common event to get the data of the current event, and if its different from the last time it was called, reset the array. if not, keep it and continue splicing off of the old one.
Re-declare the array?

So something like
JavaScript:
const originalArray = Array.from({ length: 10}, (_, index) => index + 1);
to declare the original array.

Then set a variable to the original array (control variables>script>originalArray) and then splice that variable.
JavaScript:
$gameVariables.value(n).splice(Math.randomInt($gameVariables.value(n).length), 1)
where n is the variable ID. Be sure not to set the variable more than once if you don't want to reset it just yet.

When you want to reset the array just do the same old control variables>script>originalArray again.
As said above - just do whatever you did to make the array in the first place.

Original thread: https://forums.rpgmakerweb.com/threads/arrays-and-splicing-results.163191/