The problem is oTok doesn't have a property of sTID in this line: addTokenTurn( oTok.sTID , 10); oTok is a Roll20 object, which means it as a property of .id, and a bunch of properties accessible with the .get() function. Give this a try: !att @{target|token_id} With this script: on('ready',()=>{
/* eslint-disable no-unused-vars */
const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder')));
const getTurnArrayFromPrev = (prev) => ( '' === prev.turnorder ? [] : JSON.parse(prev.turnorder));
const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)});
const addTokenTurn = (id, pr) => setTurnArray([...getTurnArray(), {id,pr}]);
const addCustomTurn = (custom, pr) => setTurnArray([...getTurnArray(), {id:"-1",custom,pr}]);
const removeTokenTurn = (tid) => setTurnArray(getTurnArray().filter( (to) => to.id !== tid));
const removeCustomTurn = (custom) => setTurnArray(getTurnArray().filter( (to) => to.custom !== custom));
const clearTurnOrder = () => Campaign().set({turnorder:'[]'});
const packTo = (to) => [{id:'HEADER',pr:Number.MAX_SAFE_INTEGER},...to].reduce((m,t)=>{
if('-1'===t.id){
m[m.length-1].packed=[...(m[m.length-1].packed || []), t];
return m;
}
return [...m,t];
},[]);
const unpackTo = (pTo) => pTo.reduce((m,t)=>{
let packed = t.packed||[];
delete t.packed;
if('HEADER' === t.id){
return [...packed,...m];
}
return [...m,t,...packed];
},[]);
const sorter_asc = (a, b) => ('-1' === a.id || '-1' === b.id) ? 0 : a.pr - b.pr;
const sorter_desc = (a, b) => ('-1' === a.id || '-1' === b.id) ? 0 : b.pr - a.pr;
const sortTurnOrder = (sortBy = sorter_desc) => Campaign().set({turnorder: JSON.stringify(unpackTo(packTo(getTurnArray()).sort(sortBy)))});
/* eslint-enable no-unused-vars */
on('chat:message',msg=>{
if('api'===msg.type && /^!att(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){
let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
//////////////////////////////////////////////////////////////////
// ADD TO TURN TRACKER
// Get initial variables
let args = msg.content.split(/\s+/).slice(1);
args.forEach(id=>{
let oTok = getObj('graphic', id);
if(oTok){
addTokenTurn(oTok.id,10);
}
});
}
});
});