The macro is for applying a Readied Action. I have a Ready Action state to mark tokens that are readied.
The intent of the macro is to first check to make sure the token is in the initiative. Second it checks if the token has the Readied Action state. If the state is not turned on, the macro turns the state on.
If the state is already turned on, then intent is to have the program turn off the "Readied Action" state, prompt for the new Initiative value for the token, apply the new value token, then sort the initiative to put the tokens into the correct order.
The first two steps seem to be working fine - the macro stops if the token isn't in the initiative, and it will turn on the Readied Action state. However, if I apply it to a token that already has the Readied Action state, then I get the following error in the chat:
java.lang.NullPointerException error executing expression .
Here is my code for reference. Please let me know if I need to clarify anything:
CODE
Code: Select all
<!--- confirm Token is in Initiative --->
[h: init = getInitiative()]
[h: newInit = ""]
[h: assert(isNumber(init),"Ready Action only applies to tokens in Initiative", 0)]
<!--- Check for current State value --->
[h: stateName = "ReadyAction"]
[h: currentStatus = getState(stateName)]
<!--- set State and adjust Initiative order --->
[h, if(currentStatus == 0): setState(stateName, 1);]
[h, if(currentStatus == 1), CODE:
{
[h: setState(stateName, 0)]
[h: input("newInit|"+init+"|Enter New Initiative",)]
[h: setInitiative(newInit)]
[h: sortInitiative()]
}]