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

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

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

Post by jfrazierjr »

UntoldGlory wrote: Bear in mind that "WeaponUsed" is a property I'm adding to my sheet, and my players will just update it to be weapon 1 (primary on hand), weapon 2 (ranged), or weapon 3 (secondary or off hand).

Code: Select all

<Attack>
[/quote]

This is one of the reasons I took the extra work on to expand my properties from the base.  In this example you quote, your bow gets your strength bonus.   That's broken...   What I did was to duplicate EVERY property for each weapon that already exists(plus added additional ones on top) and added something Like:

Weapon1Stat
Weapon2Stat
Weapon3Stat
CurrentWeaponStat (but you could use WeaponUsedStat or whaever)


Then, I have a macro to say "switch to Blah" as the label and the body does the assignment with the whole qoute thing trick:

[CurrentWeaponStat = "Weapon1Stat"]
[CurrentWeaponDmg= "Weapon1Dmg"]

Repeat as many times as you have weapon properties.   Then update your macro to use the currentWeapon* property and it just does the right thing.  Bottom line, the player clicks his "Change weapon to x" macro and everything self adjusts...
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
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

Another good thing is that no matter how many weapons you add as properties, you make one macro for each attack, one macro to switch to weapon x and you are done. If someone needs to add Weapon4*, then they make one macro and a few properties and the best part is that they have to modify ZERO macros, period, because you are building your attack macros with no knowledge of Weaponx* properties, only CurrentWeapon* or WeaponUsed* or whatever you determine to call it....

Likewise if someone wants to add a 5th, 6th,etc weapon...
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
kat2cute
Dragon
Posts: 297
Joined: Wed Jan 30, 2008 3:46 pm

Post by kat2cute »

I am attempting to use the if statement to make a D&D 3.0 magic missile. You get a varying number of missiles depending on your caster level, but they always do the same damage. Here is what I came up with. I tried putting + " Force Damage " inside the true condition after the roll, but it would eat it. Very odd. Anyways, enjoy and try to improve it!

Code: Select all

{MissileNum=min(5,1+floor((CasterLevel-1)/2))} <b>Magic Missiles!</b><hr/> Up to 5 targets, no 2 more than 15 ft apart
Lvl 1; Comp: V,S; {100+10*CasterLevel} ft range;  SR
<b>{if(MissileNum >= 1,roll(1,4)+1 , "")}</b> Force Damage
<b>{if(MissileNum >= 2, roll(1,4)+1 , "")}</b> 
<b>{if(MissileNum >= 3, roll(1,4)+1, "")}</b> 
<b>{if(MissileNum >= 4, roll(1,4)+1 , "")}</b> 
<b>{if(MissileNum >= 5, roll(1,4)+1 , "")}</b> 
<!--[Spells1Remaining = Spells1Remaining-1]-->
Love the new parser options.

Code: Select all

Huge<b> FIREBALL!</b><hr/> 20ft radius, <b>{eval(min(10,CasterLevel) + "d" + "6"))}</b> Fire Damage<br>Lvl 3; Comp: V,S,M; {400+40*CasterLevel} ft range;  <br>DC {10+IntMod+3} Reflex half, SR
<!--[Spells3Remaining = Spells3Remaining-1]-->
Quote from an underwater D&D fight:
Alright fighter, it's your turn. What do you do?
Fighter: What do you think I do? I FAIL MY F**KING SWIM CHECK

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

Post by BigO »

Mathemagician wrote:What do you mean rolling a die inside an if statement doesn't work?

{if(1>0,2d20+20,1d4-10)} and the like seem to work just fine..
Hmm. Ok. Didn't work for me yesterday.

--O

User avatar
UntoldGlory
Great Wyrm
Posts: 1649
Joined: Sun Mar 16, 2008 8:12 pm

Post by UntoldGlory »

Thanks for the responses guys. Good call jfraz, I totally forgot about the need to switch stats *smackforehead*. I was really stuck on the fact that currently my one fighter is the only guy that switches weapons, and never seems to use a ranged weapon.


I'll probablly use your method, can you PM me your full macros and properties list?

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

jfrazierjr wrote:
UntoldGlory wrote: Bear in mind that "WeaponUsed" is a property I'm adding to my sheet, and my players will just update it to be weapon 1 (primary on hand), weapon 2 (ranged), or weapon 3 (secondary or off hand).

Code: Select all

<Attack>
[/quote]

This is one of the reasons I took the extra work on to expand my properties from the base.  In this example you quote, your bow gets your strength bonus.   That's broken...   What I did was to duplicate EVERY property for each weapon that already exists(plus added additional ones on top) and added something Like:

Weapon1Stat
Weapon2Stat
Weapon3Stat
CurrentWeaponStat (but you could use WeaponUsedStat or whaever)


Then, I have a macro to say "switch to Blah" as the label and the body does the assignment with the whole qoute thing trick:

[CurrentWeaponStat = "Weapon1Stat"]
[CurrentWeaponDmg= "Weapon1Dmg"]

Repeat as many times as you have weapon properties.   Then update your macro to use the currentWeapon* property and it just does the right thing.  Bottom line, the player clicks his "Change weapon to x" macro and everything self adjusts...[/quote]

See I'm working on that generic case now, but I'm a bit behind on it.  The trouble comes in that I'm ALSO trying to build a few other things in...and there are some SERIOUS implications for that.  It gets really complex to do all that eventually.
0+0=1, for very unstable CPUs.

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

Post by jfrazierjr »

UntoldGlory wrote:Thanks for the responses guys. Good call jfraz, I totally forgot about the need to switch stats *smackforehead*. I was really stuck on the fact that currently my one fighter is the only guy that switches weapons, and never seems to use a ranged weapon.


I'll probablly use your method, can you PM me your full macros and properties list?
I can.. just remember that I am still working on tweaking and I am one of those that really likes derived values. I would rather add in a new property when I feel it's needed and fix 5 characters than modify 150 macros. I tend to want to make properties for everything and will continue to do so until Chartool can do the mapping. I can't say for sure I have added everything I want to add, nor have I removed things that I am not 100% sure I need yet. With the ability to hide stuff in html comments, I will probably add more than I will take away though...

I will post up a zip file with my current(unfinished) tokens and properties that you can look at. I don't really have an idea about how to fix the whole two different weapon problem, and really, don't know that I will make it into an issue in my group's campaign.
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
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

Orchard wrote: See I'm working on that generic case now, but I'm a bit behind on it. The trouble comes in that I'm ALSO trying to build a few other things in...and there are some SERIOUS implications for that. It gets really complex to do all that eventually.

FOCUS MAN, FOCUS..... :roll:

Anyway, I already did some of this myself.
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
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

jfrazierjr wrote:
Orchard wrote: See I'm working on that generic case now, but I'm a bit behind on it. The trouble comes in that I'm ALSO trying to build a few other things in...and there are some SERIOUS implications for that. It gets really complex to do all that eventually.

FOCUS MAN, FOCUS..... :roll:

Anyway, I already did some of this myself.
Yes, but aren't you using 4e? I am playing 3.x on the other hand (I like to refer to it as 3.38 edition, because I really HATE some of the things they nerfed in 3.5, and refuse to honor some of the changes).

And so while the macro itself is useful as a method study, I need to rewrite for the mechanics and insanity of my particular campaign.
0+0=1, for very unstable CPUs.

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

Post by jfrazierjr »

Orchard wrote:
jfrazierjr wrote:
Orchard wrote: See I'm working on that generic case now, but I'm a bit behind on it. The trouble comes in that I'm ALSO trying to build a few other things in...and there are some SERIOUS implications for that. It gets really complex to do all that eventually.

FOCUS MAN, FOCUS..... :roll:

Anyway, I already did some of this myself.
Yes, but aren't you using 4e? I am playing 3.x on the other hand (I like to refer to it as 3.38 edition, because I really HATE some of the things they nerfed in 3.5, and refuse to honor some of the changes).

And so while the macro itself is useful as a method study, I need to rewrite for the mechanics and insanity of my particular campaign.
AH! I did not think of that... I am GMing 4E, playing in a heavily modified FTF 3.5 game (STILL trying to convince my DM to use Maptool at the table.) and might be part of a 4E game with the same FTF players with a different player being the GM and the two swapping sessions.
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
Jaybee
Cave Troll
Posts: 38
Joined: Thu Jul 31, 2008 5:50 am

Referring to Images in a Macro and IF statement

Post by Jaybee »

I'm trying to display an image from an IF statement.
The reference

Code: Select all

<img src=file:///C:/Users/Spyrer/.maptool/TL3.jpg>
works fine. "C:/Users/Spyrer" is obviously a reference to my PC.

Even

Code: Select all

<table><tr><td></td><img src=file:///C:/Users/Spyrer/.maptool/TL3.jpg></tr></table>.
But:

Code: Select all

<!-- [img="<img src=file:///C:/Users/Spyrer/.maptool/"]-->
 <!--{TLtile=1d3}-->
	{if(TLtile== 3, "<img src=file:///C:/Users/Spyrer/.maptool/TL3.jpg>", "")}
	{if(TLtile== 2, "<img src=file:///C:/Users/Spyrer/.maptool/TL3.jpg>", "")}
	{if(TLtile== 1, "<img src=file:///C:/Users/Spyrer/.maptool/TL3.jpg>", "")}
produces:
Could not execute the command: line 1:31: expecting '"', found ' '
Any suggestions?

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

Post by Mathemagician »

BigO posted this in the Announcements thread:
BigO wrote:Don't know if this is a bug or intentional, but it's definitely something that changed with b39. In b38, this code:

Code: Select all

{if(Roll>18 && Roll < 20, " <img src='asset://c3f9e12cce5c217c52249b0c47562fc6'> ", "")}
Would show you a picture of a d20 with the 19 on top if the roll was 19, but in b39 it throws an error. I was all set to whine about it on the forums until I noticed that if you take out the slashes, it works fine:

Code: Select all

{if(Roll>18 && Roll < 20, " <img src='asset:c3f9e12cce5c217c52249b0c47562fc6'> ", "")}
Again, perhaps this was intentional and not a bug, but if that's the case I'd like to know the reason behind the change in behavior.

(And before you say it, I'm aware that == would make that line shorter in b39.)
Does that help?

Also in your if statement, you use TL3 every time, an innocent oversight but I thought I'd point it out :)

You could also maybe get away with,

Code: Select all

{"<img src=file:///C:/Users/Spyrer/.maptool/TL"+1d3+".jpg>"}
but this is dodging the issue :)

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

Repeating images

Post by Jaybee »

Nope..sorry but

Code: Select all

{"<img src=file:///C:/Users/Spyrer/.maptool/TL"+1d3+".jpg>"}
doesn't seem to work. I get a
Could not execute the command: line 1:16: unexpected char: '{'
error.

Actually your suggested code can save me a lot of time and coding since I don't have to do the elaborate IF statement - If I could get it working.

The idea is to generate random Map or Rooms with about 5x5 tiles (for a start).

Code: Select all

<!--Define variables -->
<table width=100% border=1 cellspacing="0" cellpadding="0">
  <tr>
    <!--{TLtile=1d3}-->
	{if(TLtile== 3, "<td>TL3.jpg</td>", "")}
	{if(TLtile== 2, "<td>TL2.jpg</td>", "")}
	{if(TLtile== 1, "<td>TL1.jpg</td>", "")}
    <!--{TCtile1=1d3}-->
	{if(TCtile1== 3, "<td>TC3.jpg</td>", "")}
	{if(TCtile1== 2, "<td>TC2.jpg</td>", "")}
	{if(TCtile1== 1, "<td>TC1.jpg</td>", "")}
    <!--{TCtile2=1d3}-->
	{if(TCtile2== 3, "<td>TC3.jpg</td>", "")}
	{if(TCtile2== 2, "<td>TC2.jpg</td>", "")}
	{if(TCtile2== 1, "<td>TC1.jpg</td>", "")}
    <!--{TCtile3=1d3}-->
	{if(TCtile3== 3, "<td>TC3.jpg</td>", "")}
	{if(TCtile3== 2, "<td>TC2.jpg</td>", "")}
	{if(TCtile3== 1, "<td>TC1.jpg</td>", "")}
    <!--{TRtile=1d3}-->
	{if(TRtile== 3, "<td>TR3.jpg</td>", "")}
	{if(TRtile== 2, "<td>TR2.jpg</td>", "")}
	{if(TRtile== 1, "<td>TR1.jpg</td>", "")}
  </tr>
  <tr>
    <!--{MLtile=1d3}-->
	{if(MLtile== 3, "<td>ML3.jpg</td>", "")}
	{if(MLtile== 2, "<td>ML2.jpg</td>", "")}
	{if(MLtile== 1, "<td>ML1.jpg</td>", "")}
    <!--{MCtile1=1d3}-->
	{if(MCtile1== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile1== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile1== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile2=1d3}-->
	{if(MCtile2== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile2== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile2== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile3=1d3}-->
	{if(MCtile3== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile3== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile3== 1, "<td>MC1.jpg</td>", "")}
    <!--{MRtile=1d3}-->
	{if(MRtile== 3, "<td>MR3.jpg</td>", "")}
	{if(MRtile== 2, "<td>MR2.jpg</td>", "")}
	{if(MRtile== 1, "<td>MR1.jpg</td>", "")}
  </tr>
  <tr>
    <!--{MLtile=1d3}-->
	{if(MLtile== 3, "<td>ML3.jpg</td>", "")}
	{if(MLtile== 2, "<td>ML2.jpg</td>", "")}
	{if(MLtile== 1, "<td>ML1.jpg</td>", "")}
    <!--{MCtile1=1d3}-->
	{if(MCtile1== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile1== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile1== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile2=1d3}-->
	{if(MCtile2== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile2== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile2== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile3=1d3}-->
	{if(MCtile3== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile3== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile3== 1, "<td>MC1.jpg</td>", "")}
    <!--{MRtile=1d3}-->
	{if(MRtile== 3, "<td>MR3.jpg</td>", "")}
	{if(MRtile== 2, "<td>MR2.jpg</td>", "")}
	{if(MRtile== 1, "<td>MR1.jpg</td>", "")}
  </tr>
  <tr>
    <!--{MLtile=1d3}-->
	{if(MLtile== 3, "<td>ML3.jpg</td>", "")}
	{if(MLtile== 2, "<td>ML2.jpg</td>", "")}
	{if(MLtile== 1, "<td>ML1.jpg</td>", "")}
    <!--{MCtile1=1d3}-->
	{if(MCtile1== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile1== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile1== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile2=1d3}-->
	{if(MCtile2== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile2== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile2== 1, "<td>MC1.jpg</td>", "")}
    <!--{MCtile3=1d3}-->
	{if(MCtile3== 3, "<td>MC3.jpg</td>", "")}
	{if(MCtile3== 2, "<td>MC2.jpg</td>", "")}
	{if(MCtile3== 1, "<td>MC1.jpg</td>", "")}
    <!--{MRtile=1d3}-->
	{if(MRtile== 3, "<td>MR3.jpg</td>", "")}
	{if(MRtile== 2, "<td>MR2.jpg</td>", "")}
	{if(MRtile== 1, "<td>MR1.jpg</td>", "")}
  </tr>
  <tr>
    <!--{BLtile=1d3}-->
	{if(BLtile== 3, "<td>BL3.jpg</td>", "")}
	{if(BLtile== 2, "<td>BL2.jpg</td>", "")}
	{if(BLtile== 1, "<td>BL1.jpg</td>", "")}
    <!--{BCtile1=1d3}-->
	{if(BCtile1== 3, "<td>BC3.jpg</td>", "")}
	{if(BCtile1== 2, "<td>BC2.jpg</td>", "")}
	{if(BCtile1== 1, "<td>BC1.jpg</td>", "")}
    <!--{BCtile2=1d3}-->
	{if(BCtile2== 3, "<td>BC3.jpg</td>", "")}
	{if(BCtile2== 2, "<td>BC2.jpg</td>", "")}
	{if(BCtile2== 1, "<td>BC1.jpg</td>", "")}
    <!--{BCtile3=1d3}-->
	{if(BCtile3== 3, "<td>BC3.jpg</td>", "")}
	{if(BCtile3== 2, "<td>BC2.jpg</td>", "")}
	{if(BCtile3== 1, "<td>BC1.jpg</td>", "")}
    <!--{BRtile=1d3}-->
	{if(BRtile== 3, "<td>BR3.jpg</td>", "")}
	{if(BRtile== 2, "<td>BR2.jpg</td>", "")}
	{if(BRtile== 1, "<td>BR1.jpg</td>", "")}
  </tr>
</table>
But this is kinda elaborate.
Thanks though. Will keep looking.

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

Sorted

Post by Jaybee »

This was actually even iesier than I expected.

Code: Select all

<!--Define variables -->
<table width=100% border=0 cellspacing="0" cellpadding="0">
  <tr>
<img src=file:///c:/users/spyrer/.maptool/TL{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/TC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/TC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/TC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/TR{1d3}.jpg>
  </tr>
  <tr>
<img src=file:///c:/users/spyrer/.maptool/ML{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MR{1d3}.jpg>
  </tr>
   <tr>
<img src=file:///c:/users/spyrer/.maptool/ML{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MR{1d3}.jpg>
  </tr>
    <tr>
<img src=file:///c:/users/spyrer/.maptool/ML{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/MR{1d3}.jpg>
  </tr>
   <tr>
<img src=file:///c:/users/spyrer/.maptool/BL{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/BC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/BC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/BC{1d3}.jpg>
<img src=file:///c:/users/spyrer/.maptool/BR{1d3}.jpg>
  </tr>
</table>
The result is spectacular:Image

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

Post by Mathemagician »

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!!"

Post Reply

Return to “Documentation Requests/Discussion”