I am making a crafting calculator on google sheets and all was going well until a script which had run fine before mysteriously stopped working. With some debugging I found that the rest of this while loop is working fine, including the else statement. I have also confirmed that the if condition does become true on the line above the if statement. However, when it checks the if condition within the statement, the application hangs and eventually times out.
// Convert data into an array of craftables and an array of ingredients
var con = true;
var w = 3;
while(con) {
debug.setValue("Array filler loop " + (w - 2).toString());
var val = recipesSheet.getRange(w, 1);
//debug.setValue("val.isBlank() is " + val.isBlank());
if (val.isBlank()) {
debug.setValue("No more recipes after " + (w - 2).toString() + " loops");
con = false;
break;
} else {
craftables.push(val.getValue());
//debug.setValue("Added " + val.getValue() + " to craftables");
// Loop through ingredients
var con2 = true;
var j = 9;
while (con2) {
var ing = recipesSheet.getRange(w, j);
if (ing.isBlank()) {
con2 = false;
//debug.setValue("No more ingredients after " + (j - 8).toString() + " loops");
break;
} else {
ingredients.push(ing.getValue());
//debug.setValue("Added " + ing.getValue() + " to ingredients");
j += 2
}
}
}
I’ve tried increasing/decreasing the google sheets queries and the time out happens in the same spot, so it isn’t a quota lock (I think). However the condition is coincidentally true on the 100th loop. It’s not a timeout issue, as I usually end up terminating manually instead of waiting for the time out after it hangs for a while. It’s a special trigger not a simple trigger so the time out is 360 seconds.
It has worked once before and has not worked since. I have tried clearing cache and restarting everything. I can’t find an issue in the code.
Flux is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.