RPTools.net

Discussion and Support

Skip to content

It is currently Wed Nov 22, 2017 5:24 pm 






Reply to topic  [ 8 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: Problem with math.floor function in a macro
PostPosted: Tue Oct 31, 2017 5:52 pm 
I've added (what I think is) a very simple macro to a black pudding token for my Pathfinder campaign.

A black pudding has a Split ability that comes into play if it is struck by a piercing or slashing weapon. The rule is when struck by either a piercing or slashing weapon and the pudding has more than 10 HP, the pudding splits into two identical puddings each with half the hit points (rounded down because it is Pathfinder) of the original. I decided to automate this by adding a macro to the token that would do the dividing on the current token, then I can just copy and paste it to create the duplicate. Seems pretty straightforward.

FYI, the token has properties for HP and MaxHP. I also added printed lines (e.g., [r: "line 1"], [r: "line 2"], etc.) between each of the macro steps to see where the problem lies - it didn't even get through the first step, so I really am stuck. The other weird thing is the macro changes the value of the HP property to a null set before throwing the error.

Here's what I wrote:
Code:
[h: HP=getProperty(HP)]
[h: assert(HP>10, "A Black Pudding with 10 or fewer HP cannot split")]
[h: NewHP=(HP/2)]
[h: NewHP=math.floor(NewHP)]
[h: setProperty(HP, NewHP)]
[h: setProperty(MaxHP, NewHP)]


I can't see any glaring errors, but when I run the macro the chat returns "illegal argument type java.lang.String, expecting java.math.BigDecimal"

That makes me think the program must be seeing the HP variable as a text string rather than a number, but I'm not sure how to make it realize that's not the case since the HP property is only ever a number.

Any help is greatly appreciated.


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Tue Oct 31, 2017 6:31 pm 
TheIneffableCheese wrote:
That makes me think the program must be seeing the HP variable as a text string rather than a number, but I'm not sure how to make it realize that's not the case since the HP property is only ever a number.

You can check if a value is a number by using Wiki: isNumber().

And you can try to change something into a number with Wiki: number().

EDIT:

And now that I've said the above I went and tested your code in my framework since I have a HP property... and wouldn't ya know... it thinks my HP property is a string, too (Wiki: isNumber() confirms). The error is not with math.floor though, it's with the assert which expects either a 0 or a 1 (the error is thrown with only the first two lines of your code).

Strange thing is I can't get Wiki: number() to force my HP value into a number. It throws the error:

Code:
Argument number 1 "" to function "number" must be a number.


So... not sure what the problem is...

_________________
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7949
Location: Bay Area
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Tue Oct 31, 2017 8:19 pm 
Is HP blank? Does HP have a default value? Is HP a global variable? If it's global, then the first line essentially says HP = HP. Also, for my asserts I usually put ,0 at the end to trim the message.

You could test these like this:
Code:
[H: assert(! json.isEmpty(HP),"HP has a blank value",0)]
[H: assert(! isNumber(HP),"HP is not a value",0)]

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Tue Oct 31, 2017 8:39 pm 
Can't speak for the op but in my case...
aliasmask wrote:
Is HP blank?

Nope. Character I tested it on had a value of 31 in the HP property.

Quote:
Does HP have a default value?

My campaign has a 10 default.

Quote:
Is HP a global variable? If it's global, then the first line essentially says HP = HP.

Not sure what you mean with this.

Quote:
You could test these like this:
Code:
[H: assert(! json.isEmpty(HP),"HP has a blank value",0)]
[H: assert(! isNumber(HP),"HP is not a value",0)]

Running that I get the "not a value" result... which was expected because I already knew that Wiki: isNumber() does not see the value as a number (like I suspect is the OP's problem.) But I use all kinds of math on HP's in other macros... not the least of which on a damage :

Code:
[h: HP = HP - damage]

So I'm not sure how that can be if it's a string and not a number.

_________________
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7949
Location: Bay Area
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Tue Oct 31, 2017 11:09 pm 
Derp!

What's wrong with this line?

Code:
[h: HP=getProperty(HP)]


The same thing that is wrong with these lines:

Code:
[h: setProperty(HP, NewHP)]
[h: setProperty(MaxHP, NewHP)]

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9419
Location: Netherlands
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Wed Nov 01, 2017 2:47 am 
missing quotes !

_________________
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
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Wed Nov 01, 2017 3:01 am 
aliasmask wrote:
Derp!

What's wrong with this line?

*Sigh*

It's always something silly. ;)

I just cut-n-pasted... and then when I tested isNumber I went down the same rabbit hole. I had a character sheet open so I never saw that the property was being jacked. Doh.

To the OP:

You need quotes around the Token Property:

Code:
[h: HP = getProperty("HP")]


And, in general, I wouldn't use a temporary variable that is token property. If you run the macro on the token it will change the variable. To keep things clear, I usually only use capitalized variables when I am using a token property. Otherwise I only use lowercase variables.

Code:
[h: hpCheck = getProperty("HP")]
[h: noSplit = if(hpCheck > 10, 1, 0)]
[h: assert(noSplit, "A Black Pudding with 10 or fewer HP cannot split")]
[h: newHP = floor(hpCheck/2)]
[h: setProperty ("HP", newHP)]
[h: setProperty ("MaxHP", newHP)]

_________________
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


Top
 Profile  
 
User avatar  Offline
Cave Troll
 
Joined: Sun Mar 22, 2015 2:57 pm
Posts: 40
 Post subject: Re: Problem with math.floor function in a macro
PostPosted: Wed Nov 01, 2017 5:27 pm 
wolph42 wrote:
missing quotes !

D'oh!

I knew it had to be something stupid I had missed. :roll:

Thanks all. I just reworked the macro and it's working like a champ. :D

Also, thanks for the best practices advice on variable naming - I'll hold on to that for the future.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 8 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 is 1 user online :: 0 registered, 0 hidden and 1 guest (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 1 guest





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

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman