Question on eval

Developer discussion regarding MapTool 1.4

Moderators: Azhrei, dorpond, trevor

Forum rules
Posting now open to all registered forum users.
Post Reply
taustinoc
Dragon
Posts: 429
Joined: Mon Aug 03, 2015 6:30 pm

Question on eval

Post by taustinoc »

What should happen with eval("0")?

When I type it into the chat window, the output is 0.

But when I pull a list of values from a table, and separate them with listGet, and the result of a particular entry is 0, I get "Illegal argument type java.math.BigDecimal, expecting java.lang.String" I have confirmed that what's being passed to eval is "0".

Not a huge deal, I can work around it with an if, though if I want another fixed value (say, 10), I have to use 1d1+9. It'd be nice to figure this out.

This is 1.4.0.5. Haven't tested it with any other version.

Phergus
Deity
Posts: 7108
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Question on eval

Post by Phergus »

Hmm. If I do any of these in the chat window it works fine.

Code: Select all

[isNumber(eval("0"))]
[equals(eval("0"),1)]
[math.asin(eval("0"))]
[eval("0")+2]
They all return the expected result.

User avatar
aliasmask
Deity
Posts: 8580
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Question on eval

Post by aliasmask »

There is some type casting when pulling from the list where a number it typed as a number and not a string. eval() only works on strings.

So, try eval(string(listGet(list,0)))

taustinoc
Dragon
Posts: 429
Joined: Mon Aug 03, 2015 6:30 pm

Re: Question on eval

Post by taustinoc »

That makes sense. And fixed it. Thanks.

Post Reply

Return to “MapTool 1.4”