So I am trying to work on this script that will send a token to the back and keep it there. It was working fine yesterday and today its the one script crashing my game. Could someone take a look at this code and give me insight on it? Perhaps suggest a better way to do it? Since the AoE scripts are currently not working for Jumpgate, I was using this as a quick fix to toss an AoE token on the board and keep it out of the way. Good idea in theory, but my programming skills are remedial at best. EDIT: The script doesn't crash at startup, but when I bring any other token and put it on the board. Or move it, then it crashes. on('ready',()=>{
const lookWhere = [
'bar1_value',
'bar1_max',
'bar2_value',
'bar2_max',
'bar3_value',
'bar3_max',
'name',
'gmnotes'
];
const regex = /\[back\]/i;
const DELAY = 100;
const checkAndSendBack = (obj) => {
if (lookWhere.find(k => regex.test(decodeURIComponent(obj.get(k) || '')))) {
toBack(obj);
}
};
// When a graphic is added
on('add:graphic', (obj) => {
let id = obj.id;
let limit = 5;
const check = () => {
let graphic = getObj('graphic', id);
if (graphic) {
checkAndSendBack(graphic);
} else if (--limit) {
setTimeout(check, DELAY);
}
};
setTimeout(check, DELAY);
});
// Ensure token stays in the back when moved or modified
on('change:graphic', (obj) => {
checkAndSendBack(obj);
});
});