Why can I eval() a number, and how can I?

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
Shadow Wizard
Giant
Posts: 221
Joined: Mon Apr 11, 2011 8:11 pm

Why can I eval() a number, and how can I?

Post by Shadow Wizard »

I have a variable, that can either be a string that represents an evaluatable expression ("1d6") or a number (100) depending what is stored in it. Either way, when it is "Executed" it will result in a number. I am having a hard time getting maptool to deal with it if it is a number.
Even when I check to see if it a number first, it still seems to fail, as it seems to need to perform both options of an if function even if it doesn't need to use one of them.
So, how do I get this wo work?

[h:odb=json.get(selattackjson, "Other damage bonus")] (odb can be either a number (100) or a roll to make (1d6))
[h:odb=if(isNumber(odb)==1,odb,eval(odb))]

even with this, I get the same errors as if I try and eval(100) even though I am telling it NOT to eval(100)

User avatar
aliasmask
RPTools Team
Posts: 9150
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Why can I eval() a number, and how can I?

Post by aliasmask »

Common problem. Just add string().

[H: mod = eval(string(modText))]

Shadow Wizard
Giant
Posts: 221
Joined: Mon Apr 11, 2011 8:11 pm

Re: Why can I eval() a number, and how can I?

Post by Shadow Wizard »

Thank you.

Post Reply

Return to “Macros”