RPTools.net

Discussion and Support

Skip to content

It is currently Mon Nov 20, 2017 9:32 pm 






Reply to topic  [ 5 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Cave Troll
 
Joined: Sun Mar 22, 2015 2:57 pm
Posts: 40
 Post subject: Confused about a macro error
PostPosted: Tue Nov 14, 2017 2:45 am 
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:

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



Top
 Profile  
 
 Offline
Kobold
 
Joined: Thu Oct 19, 2017 11:36 am
Posts: 19
 Post subject: Re: Confused about a macro error
PostPosted: Tue Nov 14, 2017 4:58 am 
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.

Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9419
Location: Netherlands
 Post subject: Re: Confused about a macro error
PostPosted: Tue Nov 14, 2017 7:47 am 
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.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7947
Location: Bay Area
 Post subject: Re: Confused about a macro error
PostPosted: Tue Nov 14, 2017 7:51 am 
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:
<!--- 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)]
}]

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Cave Troll
 
Joined: Sun Mar 22, 2015 2:57 pm
Posts: 40
 Post subject: Re: Confused about a macro error
PostPosted: Tue Nov 14, 2017 5:41 pm 
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 5 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 3 guests





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman