RPTools.net

Discussion and Support

Skip to content

It is currently Mon Dec 11, 2017 10:24 am 






Reply to topic  [ 13 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Why does this always return false?
PostPosted: Mon Nov 20, 2017 9:26 pm 
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:
[h:if(RollInit=="Y",setInitiative(1),setInitiative(5))]


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7964
Location: Bay Area
 Post subject: Re: Why does this always return false?
PostPosted: Mon Nov 20, 2017 10:11 pm 
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.

_________________
Downloads:


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Mon Nov 20, 2017 10:16 pm 
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.


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Mon Nov 20, 2017 10:48 pm 
Never mind. I started over with the Roll Option instructions, and got it figured out.


Top
 Profile  
 
 Offline
Cave Troll
 
Joined: Thu Oct 19, 2017 11:36 am
Posts: 26
 Post subject: Re: Why does this always return false?
PostPosted: Tue Nov 21, 2017 4:58 am 
Was RollInit a campaign property ?

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


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Tue Nov 21, 2017 11:13 am 
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.


Top
 Profile  
 
 Offline
Cave Troll
 
Joined: Thu Oct 19, 2017 11:36 am
Posts: 26
 Post subject: Re: Why does this always return false?
PostPosted: Tue Nov 21, 2017 12:14 pm 
Then let's blame the maptool macro parser :mrgreen:


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Tue Nov 21, 2017 12:23 pm 
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.


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Mon Oct 26, 2009 4:51 am
Posts: 306
 Post subject: Re: Why does this always return false?
PostPosted: Tue Nov 21, 2017 6:42 pm 
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.


Top
 Profile  
 
 Offline
Cave Troll
 
Joined: Thu Oct 19, 2017 11:36 am
Posts: 26
 Post subject: Re: Why does this always return false?
PostPosted: Wed Nov 22, 2017 5:57 am 
thanks for the explanation.

This macro language is puzzling.


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Wed Nov 22, 2017 11:34 am 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6319
Location: Middle of Nowhere, NM
 Post subject: Re: Why does this always return false?
PostPosted: Wed Nov 22, 2017 2:13 pm 
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:
[somevariable = if( hitpoints <= 0, "He's dead, Jim.", "Still hanging on.")]


Or just where it reads some property or state condition.

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


Top
 Profile  
 
 Offline
Giant
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 227
 Post subject: Re: Why does this always return false?
PostPosted: Wed Nov 22, 2017 2:31 pm 
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 13 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