Been playing with this for a couple of hours now, and it is working as intended. When I switched from an encounter map to a larger dungeon map, simply adding all the tokens wasn't good enough. I wanted to be able to selectively add tokens, and have it retain the original initiative for all currently in the initiative panel. This allows me to add creatures not yet in the encounter to the encounter, and when the players' turns come up, they get to "roll". (Although I have to be careful to have the chat window visible at the time or they have to tell me over voice.)
Code: Select all
[h, foreach(tid, getSelected()), code: {
[switchToken(tid)]
[addToInitiative()]
}]
[h: tokens = json.get(getInitiativeList(), 'tokens')]
[h, foreach (token, tokens, ''), code: {
[tid = json.get(token, 'tokenId')]
[switchToken(tid)]
[if (getInitiative() == 'null'), code: {
[init = (if(Init == '', 0, Init))]
[if (isNPC(tid)), code: {
[setInitiative(1d20 + init + init/10 + d100/1000)]
};{
input('roll')
[setInitiative(roll + init + init/10 + d100/1000)]
}]
};{}]
[broadcast(getName(tid) +' init: ' + getInitiative(), 'gm')]
}]
[h: sortInitiative()]
I must be missing something obvious. I've gone through and checked all the brackets, braces and parens, but maybe someone can enlighten me?Error in body of roll. Statement options (if any): h, foreach (token, tokens, ''), code Statement Body (first 200 characters): { [h: tid = json.get(token, 'tokenId')] [h: switchToken(tid)] [h, if (getInitiative() == 'null'), code: { [h: init = (if(Init == '', 0, Init))] [h, if (isNPC(tid)), code:
Here's what it looks like without the broadcast:
Code: Select all
[h, foreach(tid, getSelected()), code: {
[switchToken(tid)]
[addToInitiative()]
}]
[h: tokens = json.get(getInitiativeList(), 'tokens')]
[h, foreach (token, tokens, ''), code: {
[tid = json.get(token, 'tokenId')]
[switchToken(tid)]
[if (getInitiative() == 'null'), code: {
[init = (if(Init == '', 0, Init))]
[if (isNPC(tid)), code: {
[setInitiative(1d20 + init + init/10 + d100/1000)]
};{
input('roll')
[setInitiative(roll + init + init/10 + d100/1000)]
}]
};{}]
}]
[h: sortInitiative()]