Confused about a macro error

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
TheIneffableCheese
Cave Troll
Posts: 64
Joined: Sun Mar 22, 2015 3:57 pm

Confused about a macro error

Post by TheIneffableCheese »

I am sorry to be back with another question that's probably going to end up being something basic, but I've been over this macro code multiple times and I cannot figure out where I'm screwing things up.

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()]
	
}]


bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Confused about a macro error

Post by bobifle »

I'm absolutely no expert but there seems to be an extra comma on the "input" line.
Last edited by bobifle on Tue Nov 14, 2017 7:51 am, edited 1 time in total.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Confused about a macro error

Post by wolph42 »

bobifle wrote:I'm absolutely no expert but there's seems to be an extra comma on the "input" line.
nice catch, its always hard to scan for syntax errors.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Confused about a macro error

Post by aliasmask »

You have an extra ";". This may not cause an error, but is incorrect if you don't have a false condition statement. Also, when dealing with true/false conditions where your value is 0 or 1, then you don't need the == 0 part. if(0) where currentStatus equal 0 is perfectly valid. In that case, it's better to have a variable name that describes the true/false nature like "isStateOn".

There is an extra "," in your input line at the end. The parser is probably expecting another line for input and found null instead. I find using 'text'+var+'text' to get a bit messy sometimes and prefer to use strformat("text %{var} text") formatting instead. I find it easier to read.

I also changed the order of getting your input and setting a state. You don't want to set the state if the user aborts the input.

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: isStateOn = getState(stateName)]

<!--- set State and adjust Initiative order --->

[h, if(isStateOn), code: {
   [h: abort(input(strformat("newInit|%{init}|Enter New Initiative|TEXT")))]
   [h: setState(stateName, 0)]
   [h: setInitiative(newInit)]
   [h: sortInitiative()]   
};{
   [H: setState(stateName, 1)]
}]

User avatar
TheIneffableCheese
Cave Troll
Posts: 64
Joined: Sun Mar 22, 2015 3:57 pm

Re: Confused about a macro error

Post by TheIneffableCheese »

Thanks to all for the help. Aliasmask's code works perfectly, and is definitely more elegant than my first attempt.

Hopefully one of these days I will be able to do some of these simple things without having to ask so many questions. :D

Post Reply

Return to “Macros”