Why does this always return false?

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
taustinoc
Dragon
Posts: 516
Joined: Mon Aug 03, 2015 6:30 pm

Why does this always return false?

Post by taustinoc »

RollInit is a property of the current token. If I return the property, it shows correctly. But this always returns false, regardless of what the property is set to. There are no errors, just a result of false.

Code: Select all

[h:if(RollInit=="Y",setInitiative(1),setInitiative(5))]

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

Re: Why does this always return false?

Post by aliasmask »

Anything other that 0 or "false" returns true. So, if you have another string "This is false" it will show as true. "Y" and "N" are not reserved words like "true" and "false" which the parser translates at 1 and 0, respectively.

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

Re: Why does this always return false?

Post by taustinoc »

I have explained poorly. If the token property RollInit is "Y", the If statement should set the initiative value to 5, otherwise set it to 1. It always sets it to 5, no matter what RollInit is.

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

Re: Why does this always return false?

Post by taustinoc »

Never mind. I started over with the Roll Option instructions, and got it figured out.

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

Re: Why does this always return false?

Post by bobifle »

Was RollInit a campaign property ?

"Hidden" token properties can only be accessed through the getProperty.

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

Re: Why does this always return false?

Post by taustinoc »

It's a token property defined under Campaign Properties, and if I use it directly - say, just print it to the chat box - it works right. I had something wrong in the If statement that didn't generate any error. But I redid it from scratch using the Roll Option If instructions, and now it works. I still have no idea what was wrong before.

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

Re: Why does this always return false?

Post by bobifle »

Then let's blame the maptool macro parser :mrgreen:

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

Re: Why does this always return false?

Post by taustinoc »

bobifle wrote:Then let's blame the maptool macro parser :mrgreen:
A tempting thought, especially since the macro language is . . . non-intuitive, to me at least.

But I'm about 100% certain it was me, not MapTool.

In any event, this isn't the first time I've been completely stumped by something, posted a question here, then figured it out on my own before somebody explained it to me. So I'm going with the theory that the regulars here are so smart it makes me smarter when I see their names on the screen.

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: Why does this always return false?

Post by metatheurgist »

It's a quirk of the If() function that it evaluates both parts of the statement. That's why it's not recommended for use if you're doing something like setting the same variable with either condition, unless that variable is being set by the value returned from the expression. This is explained in the docs.

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

Re: Why does this always return false?

Post by bobifle »

thanks for the explanation.

This macro language is puzzling.

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

Re: Why does this always return false?

Post by taustinoc »

bobifle wrote:thanks for the explanation.

This macro language is puzzling.
Everything in the MapTool macro language is puzzling, but that may say more about me than it does about the language.

My takeaway from this is that the If statement isn't exactly an If-Then statement, just If. Which is weird to me. But the If roll option is If-Then. Which is weirder to me.

But I got it to work, which is what counts.

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

Re: Why does this always return false?

Post by Phergus »

The IF statement used in that form evaluates both return expressions but only returns the result corresponding with matching true/false condition.

So normally it would be used more like this:

Code: Select all

[somevariable = if( hitpoints <= 0, "He's dead, Jim.", "Still hanging on.")]
Or just where it reads some property or state condition.

Code: Select all

[weapon = if( hand == "right", getProperty("RightHand"), getProperty("LeftHand"))]

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

Re: Why does this always return false?

Post by taustinoc »

OK, I think I get it now. Still very non-intuitive to me. It's useful for reporting on something based on the condition tested, but less so for doing something based on it.

I think what's most confusing is that there's two Ifs, and they work differently.

Post Reply

Return to “Macros”