The idea behind this is that I press the macro every turn and when it comes to the end of the round, it reroll the initiative for every token in the initiative panel, it orders them and then it starts the new round.
In order to rolling the initiative, it must before get some properties (Dexterity) from those tokens and this is where it comes the trouble. If I delete the lines to get the property it works fine, but I need that (and others) properties and I can't understand why it doesn't work. This is the code:
Code: Select all
[r, IF(getCurrentInitiative() +1 == initiativeSize()), CODE:
{
[h: roundNumber = getInitiativeRound()]
[h: setCurrentInitiative(-1)]
[h, IF(roundNumber==-1): roundNumber = 0; roundNumber = roundNumber + 1]
[h: setInitiativeRound(roundNumber)]
[h: initList = getInitiativeList()]
[h: tokensdata = json.get(initList,"tokens")]
[h, foreach(token, tokensdata), CODE:
{
[h: switchToken(json.get(token,"tokenId"))]
[h: Dex = getProperty("Dexterity")]
[h: Dex = if(isNumber(Dex),floor((Dex-10)/2),0)]
[h: setInitiative(1d6)]
}]
[h: sortInitiative()]
[h: nextInitiative()]
};
{
[h: nextInitiative()]
}]