if, else if, nested if, "block" ifs: a tutorial

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Re: Sorted

Post by BigO »

Jaybee wrote:This was actually even easier than I expected.
Nice work! I'm using images a lot in my macros and I hadn't tried using one on the local drive yet, only ones hosted on the internet. It's good to know how that might work.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
Jaybee
Cave Troll
Posts: 38
Joined: Thu Jul 31, 2008 5:50 am

Shitting Bricks

Post by Jaybee »

Thanks ...did so.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

Mathemagician wrote:You know the phrase, when you're really surprised, "feces a brick?"

I suddenly now have the supplies to build an entire old-world oven...

You should post this over in "User Creations!!"
I agree 100%!!! This is awesome.


Any reason not to use tables with the references to the images instead?
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

jfrazierjr wrote:Any reason not to use tables with the references to the images instead?
Calling images stored in tables is not supported yet as of b39. However, there shouldn't be any reason you can't make a table with a list of path names and build that into your statements.

Big caveat though, that I just thought of. Don't forget that when playing over the internet if those images are only on YOUR hard drive, I don't know what will happen when you try to send that over chat to the other players. Someone should test that. One of two things will most likely happen: 1) it might try to send them over the wire to the other players. As we know, this isn't always the fastest with maptools. 2) It might not do anything to send them which means that the other person would have to be on a PC and have those images stored in the exact same place as you do, or they won't see it.

The solution to both of these problems is the same, wait til image tables are supported via macro calls (coming soon), or store the images on the internet somewhere. I have a web server, so when I need to do this I just upload them there and put the web path in the img statements. Works fine.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
hennebeck
Dragon
Posts: 394
Joined: Sun Jun 01, 2008 12:06 am
Location: THe City of Roses

Post by hennebeck »

{state.Dead = if( HP <= -Bloodied, state.Dead, )}

Make this work.
Pweeeese.

User avatar
Mathemagician
Dragon
Posts: 666
Joined: Tue May 22, 2007 2:27 pm

Post by Mathemagician »

hennebeck wrote:{state.Dead = if( HP <= -Bloodied, state.Dead, )}

Make this work.
Pweeeese.
So close.

{state.Dead=if(HP <= -Bloodied,1,0)}

User avatar
hennebeck
Dragon
Posts: 394
Joined: Sun Jun 01, 2008 12:06 am
Location: THe City of Roses

Post by hennebeck »

Thank you.
And I was assuming there would be something really wrong with making bloodied negative.

bobthedog
Cave Troll
Posts: 85
Joined: Sun Aug 03, 2008 7:17 pm

Post by bobthedog »

Okay, I'm working on an "automatic" init tracker, and if clauses have been driving me crazy.

Code: Select all

[Init = Init]
[Mod = Mod]
[Name = Name]
[TieBreak = 1d2]
[Place = 0]
[Place = if(Init > Init5, 5, Place)]
[Place = if((Init==Init5)&&(Mod>Mod5), 5, Place)]
[Place = if((Init==Init5)&&(Mod==Mod5)&&(TieBreak==1), 5, Place)]
Init, Mod and Name are user input. Init5 and Mod5 are token properties (currently set to 0).

When I run this macro, I get "invalid expression" for the last two calculations. I have tried messing around with parentheses and stuff (even trying to use or and make the Place assignment in a single line), but nothing seems to work.

Thoughts?

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

bobthedog wrote:Okay, I'm working on an "automatic" init tracker, and if clauses have been driving me crazy.

Code: Select all

[Init = Init]
[Mod = Mod]
[Name = Name]
[TieBreak = 1d2]
[Place = 0]
[Place = if(Init > Init5, 5, Place)]
[Place = if((Init==Init5)&&(Mod>Mod5), 5, Place)]
[Place = if((Init==Init5)&&(Mod==Mod5)&&(TieBreak==1), 5, Place)]
Init, Mod and Name are user input. Init5 and Mod5 are token properties (currently set to 0).

When I run this macro, I get "invalid expression" for the last two calculations. I have tried messing around with parentheses and stuff (even trying to use or and make the Place assignment in a single line), but nothing seems to work.

Thoughts?
It's failing because of Mod5. Mod is a math operator and shouldn't be used as a property name. Just name it something else and it should work.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
Mathemagician
Dragon
Posts: 666
Joined: Tue May 22, 2007 2:27 pm

Post by Mathemagician »

Actually, I think it's failing not because of mod being a math operator (I don't htink it's supported in the parser), but because of the "d5" part of it. Try changing the name from Mod5 to Modi5 or some such

bobthedog
Cave Troll
Posts: 85
Joined: Sun Aug 03, 2008 7:17 pm

Post by bobthedog »

Mathemagician wrote:Actually, I think it's failing not because of mod being a math operator (I don't htink it's supported in the parser), but because of the "d5" part of it. Try changing the name from Mod5 to Modi5 or some such
Ding! Ding! Ding! We have a winner! it was the d# bit.

Thank you, Math and Big0, for your suggestions.

/me goes back to coding

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

Mathemagician wrote:Actually, I think it's failing not because of mod being a math operator (I don't htink it's supported in the parser), but because of the "d5" part of it. Try changing the name from Mod5 to Modi5 or some such
Ahh, good call. That's what I get for not testing before I post.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

ElCucuy
Cave Troll
Posts: 50
Joined: Thu Jul 03, 2008 7:30 pm

Post by ElCucuy »

Hi folks, I'm trying to figure out this macro coding, but I'm running up against a few roadblocks. Here's my first one. And understanding what I'm doing wrong in this one, might lead me to figuring out the others.

Anyway, here's the code for a token macro that damages the character. Click the button and it prompts for the ChangeHP value. Standard stuff cobbled from around the forums.

Code: Select all

<span> 
[DamageTaken = ChangeHP] 
[TempHP = TempHP - DamageTaken] 
[HP = HP + min(0, TempHP)] 
[TempHP = max(0,TempHP)] 
[state.Dead = if(HP>0, 0, 1)] 
[state.Bloodied = if(HP <MaxHP>95, 1, 0)] 
[state.HP95=if(HPPct>90 && HPPct<95>85 && HPPct<90>80 && HPPct<85>75 && HPPct<80>70 && HPPct<75>65 && HPPct<70>60 && HPPct<65>55 && HPPct<60>50 && HPPct<55>45 && HPPct<50>40 && HPPct<45>35 && HPPct<40>30 && HPPct<35>25 && HPPct<30>20 && HPPct<25>15 && HPPct<20>10 && HPPct<15>5 && HPPct<10>0 && HPPct<=5, 1, 0)] 
[state.HP0=if(HPPct<0, 1, 0)] 
</span>Damage Taken: <b> [DamageTaken]</b>
The trick is that I want to specialize this for a DnD 4E Dragonborn character. What that means is that if his state becomes Bloodied, then I'd like it to add +1 to the property MiscAttBonus. Here's what I'm trying to add. Note that I'm trying to put this after the line that sets his Bloodied state and before the line that check for Prone.

Code: Select all

[MiscAttBonus = MiscAttBonus + if(state.Bloodied=1,1,0)]
No matter what, I'm getting a 0 back in response to the above. I've changing that ELSE response to a 2, and it still returns a 0, so I know I'm off the rails on that statement somehow, but not seeing where.

Can anyone point me in the right direction?

el Cucuy

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

ElCucuy wrote:

Code: Select all

[MiscAttBonus = MiscAttBonus + if(state.Bloodied=1,1,0)]
No matter what, I'm getting a 0 back in response to the above. I've changing that ELSE response to a 2, and it still returns a 0, so I know I'm off the rails on that statement somehow, but not seeing where.

Can anyone point me in the right direction?

el Cucuy
Ahh, such a classic programming gotcha. Try this:

Code: Select all

[MiscAttBonus = MiscAttBonus + if(state.Bloodied==1,1,0)]
One = is used for changing the value of something, == is used for comparing two values.

Don't feel bad. Everyone makes that mistake, even when you know better. Myself included.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

BigO wrote:
ElCucuy wrote:

Code: Select all

[MiscAttBonus = MiscAttBonus + if(state.Bloodied=1,1,0)]
No matter what, I'm getting a 0 back in response to the above. I've changing that ELSE response to a 2, and it still returns a 0, so I know I'm off the rails on that statement somehow, but not seeing where.

Can anyone point me in the right direction?

el Cucuy
Ahh, such a classic programming gotcha. Try this:

Code: Select all

[MiscAttBonus = MiscAttBonus + if(state.Bloodied==1,1,0)]
One = is used for changing the value of something, == is used for comparing two values.

Don't feel bad. Everyone makes that mistake, even when you know better. Myself included.
Oh, I forgot to ask what version of MapTool you're using. The == had some bugs in it when the if statement was first introduced but they have been fixed now. If it still gives you trouble then try b41 (the newest as of right now).
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

Post Reply

Return to “Documentation Requests/Discussion”