
Hi, i've been banging my head trying to fix some issues with my script. Basically, it is not always sorting my turnorder properly. I found that its failing sometimes when i have a mix of single digit and double digit values.. I think, but not sure, that it might be related to int vs string pr values, maybe someone knows and can help, as I'm not very familiar with javascript. It seems when you modify the turn order via the input box, the values get applied as a string. Adding to the tracker via rolls always adds as an int. For example, here's one of my turn order objects: [{"id":"-1","pr":2,"custom":"Second Counter"},{"id":"-JLkUe86wm_J4sEtuNhp","pr":"5","custom":"","_pageid":"7F73B956-71C3-4C5B-8C72-576EE4F15EA4"},{"id":"-JLkUZC3ZFvLfKyye_ju","pr":18,"custom":"","_pageid":"7F73B956-71C3-4C5B-8C72-576EE4F15EA4"},{"id":"-JLkcaOb-TVK1IUhn4mQ","pr":"20","custom":"","_pageid":"7F73B956-71C3-4C5B-8C72-576EE4F15EA4"}] PR values for two of the items in the array seem to be strings while the others are integers. And here's the sort function i use on the turn order: function sortJSON(turnorder, pr) {
return turnorder.sort(function(a, b) {
var x = parseFloat(a[pr]); var y = parseFloat(b[pr]);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
Any ideas? Thanks ahead of time.