Hey, I'm currently trying to make a script for 5e which rolls stats and chooses a random race, and then inputs those stats into a character sheet. For some reason however when, I try to roll the stats the API console returns an infinite loop error. The script needs a premade character sheet currently on("chat:message", function(msg) {
log(msg.content);
log(msg.type); //oddly when you input a character name that calls is associated sheet this isn't outputted to the console
if(msg.type !== "api"){ //along with the logs below
return;
}
if(msg.content.indexOf("!charGen" === 0) && msg.content.length > 6){
var charName = msg.content.substring(9, msg.content.length); //gets rid of !charGen from string
log(charName);
var characterSheet = findObjs({ type:'character', name: charName})[0]; //works in another script I've created
log(characterSheet);
if(characterSheet){
var charRace = randomInteger(races.length);
stats = [];
for(i = 0; i<6;i++){
stats[i] = statroll();
stats[i] += races[charRace-1][i];
log(stats[i]);
}
}
}
});
var races = [
[0,0,2,0,1,0,"Hill Dwarf"],
[2,0,2,0,0,0,"Mountain Dwarf"],
[0,2,0,1,0,0,"High Elf"],
[0,2,0,0,1,0,"Wood Elf"],
[0,2,0,0,0,1,"Drow"],
[0,2,0,0,0,1,"Lightfoot Halfling"],
[0,2,1,0,0,0,"Stout Halfling"],
[1,1,1,1,1,1,"Human"],
[2,0,0,0,0,1,"Dragonborn"],
[0,1,0,2,0,0,"Forest Gnome"],
[0,0,1,2,0,0,"Rock Gnome"],
[0,0,0,0,0,2,"Half-Elf"],
[2,0,1,0,0,0,"Half-Orc"],
[0,0,0,1,0,2,"Tiefling"],
];
var statroll = function(){
var rolls = [];
var rollSum;
for(i = 0; i < 4; i++){
rolls[i] = randomInteger(6);
log("roll " + rolls[i]);
}
for(j = 0; j < 3; j++){
var maxroll = 0;
var tracker;
for(k = 0; k < 4; j++){
if(rolls[k] > maxroll){
maxroll = rolls[k];
tracker = k;
}
}
rollSum += maxroll;
rolls[tracker] = 0;
}
log("total" + rollSum);
return rollSum;
};
I'm pretty to new to Javascript, so I'm worried that maybe I've messed up on syntax, or maybe I've called my function incorrectly. I've also read about the heartbeat/pulse system roll20 uses, so I'm guessing the for loops might be the issue here, however they iterate about 96 times if I've done my math right so I'm not sure why they'd cause a problem. Any help would be greatly appreciated.