this is probably the simple answer, but I really laugh, and it really breaks my brain. I am trying to assign values to variables while wading through an array.
My code is for the TTRPG tool for Discord, written in Discord.js. For this particular function, I want it to roll up videos depending on the number of players entered, and then combine all these videos and sort them. From there, I want him to snake through a sorted array to give each player a set of statuses so that each player is as close as possible to an equal playing field.
For example, if the input is 3 players, the bot will roll 3 sets of 6 stats and combine them into an array. For simplicity of explanation, we say that we flipped all the numbers from 1-18.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Will be assigned
ABCCBAABCCBAABCCBA
So that the final variables are
A = [1, 6, 7, 12, 13, 18]
B = [2, 5, 8, 11, 14, 17]
C = [3, 4, 9, 10, 15, 16]
The code that I have right now only sorts them by looping through (A, B, C, A, B, C ...), which does not average the players. I tried a bunch of different ways to get the results I need, but either the final variables are only assigned once, leaving the average variables with more statistics assigned to them, or each player variable is assigned only one stat.
, Googling "Javascript" "Snake" , , , , , . , , , , , , , !
:
if (msgContent.startsWith(".dstats ")) {
let args = msgContent.split(" ").slice(1);
var regex = /^\d+$/;
var statIndex = [];
var reply;
var forward = true;
if(regex.test(args) && args <= 10){
for(var i = 0; i < args*6; i++){
statRoll();
statIndex.push(randStat);
};
distSort = statIndex.sort(sortNumber);
for( j = 0; j < args; j++){
this['player'+j] = [];
};
var playIndex = 0;
for( f = 0; f < distSort.length; f++){
if(playIndex < args && playIndex >= 0){
this['player'+playIndex].push(distSort[f]);
}else {
playIndex = 0;
this['player'+playIndex].push(distSort[f]);
};
playIndex++;
};
reply = "Your stats blocks are as follows:\n";
for (k = 0; k < args; k++){
reply += "Player " + (k+1) +": [" + this['player'+k].join(', ') + "]\n";
};
msg.reply(reply);
}else(
msg.reply("Looks like you inputted an improper number or your number is too high. Check your command and try again!")
);
}