Macro Writing: Nesting Limits and the use of { }

Please post questions that you think belong here in the parent forum for discussion first. Then use the "Report this Post" function to alert a moderator that the post/thread should be moved. Common thread examples should not include macro programming, but rather user interface issues or usability issues.

Moderators: dorpond, trevor, Azhrei

Forum rules
Do not conduct discussion here. Do that in the parent forum.
Locked
User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Macro Writing: Nesting Limits and the use of { }

Post by Rumble »

MapTool 1.3 Release's macro language allows the nesting of operations (such as branching and looping operations) via the use of the CODE roll option and curly braces to demarcate groups of operations. However, you are restricted as to how many levels deep you can "nest" such operations. Use of the CODE block can extend only two levels deep. So this:

Code: Select all

<!--First CODE Block-->
[foreach(item, listOfItems),CODE:
{
    <!--Second CODE block, nested inside first-->
    [if(item == "Spear"),CODE:
    {
           [operation1 = "The item is a "+item]
           [operation2 = 5 + 9]
     };
     {
            [operation1 = "The item is not a "+item]
            [operation2 = 10+6]
     }]
}]
Is legitimate, as there are only 2 levels of CODE and {} used here. However this:

Code: Select all

<!--First CODE block-->
[foreach(item, listOfItems),CODE:
{
    <!--Second CODE Block-->
    [if(item == "Spear"),CODE:
    {
         <!--Third CODE Block - one nesting level too deep! -->
          [if(itemType = "LongSpear"), CODE:
         {
                [operation0 = "You get a +2 bonus with "+itemType]
         }]
           [operation1 = "The item is a "+item]
           [operation2 = 5 + 9]
     };
     {
            [operation1 = "The item is not a "+item]
            [operation2 = 10+6]
     }]
}]
will cause an error, because the nesting depth here exceeds 2.

Be aware that the nesting limit is based on how deeply nested the { } are in the code - therefore, any use of { } counts toward the nesting limits. So:

Code: Select all

[if(condition),CODE:
{
     [if(condition2),CODE:
     {
              The second condition has a value of {value}
     }]
}]
would also generate an error, as there are three levels of nested { } in that example.

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Macro Writing: Nesting Limits and the use of { }

Post by mfrizzell »

Are you sure about the third example, I only see two sets of {}. Or am I not interpreting it correctly.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Macro Writing: Nesting Limits and the use of { }

Post by Rumble »

mfrizzell wrote:Are you sure about the third example, I only see two sets of {}. Or am I not interpreting it correctly.
That's the tricky bit: the third set of { } surrounds the variable value:

Code: Select all

[if(condition),code:
{  <!-- first bracket set-->
    [if(condition),code:
    {   <!-- second bracket set-->
                    {value}  <!--third bracket set-->
    }]
}]

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Macro Writing: Nesting Limits and the use of { }

Post by mfrizzell »

That is indeed very tricky. I don't think I would have spotted that.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

Locked

Return to “WIP - User FAQ”