Nesting limits revisited

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
Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

Nesting limits revisited

Post by Holladerwaldelf »

In a FAQ post Rumble explained:
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 if I try to nest three for loops inside each other I will get an error, e.g.:

Code: Select all

[for(i,0,2,1), code: 
   {
   [output = strformat("<b>i is %{i}:</b> ")]
   [for(j,0,3,1), code:
      {
      [output = strformat("j is %{j}")]
      [for(k,0,2,1), code:
         {
         [output = strformat("<i>k is %{k}</i>")]
         }]
      }]
   [output = strformat("<br>")]
   }]

In this example I could work around that by omitting the brackets in the inner loop, i.e.:

Code: Select all

[for(i,0,2,1), code: 
   {
   [output = strformat("<b>i is %{i}:</b> ")]
   [for(j,0,3,1), code:
      {
      [output = strformat("j is %{j}")]
      [for(k,0,2,1):   output = strformat("<i>k is %{k}</i>")]
      }]
   [output = strformat("<br>")]
   }]

But if I understand it correctly there is no way to have three nesting for-loops where each has more than one command, or is there a way to work around this limitation?

I run into the same problem when I want an if-comparison inside two nesting for loops (with more than one command), e.g.:

Code: Select all

[for(i,0,2,1), code: 
   {
   [output = strformat("<b>i is %{i}:</b> ")]
   [for(j,0,3,1), code:
      {
      [output = strformat("j is %{j}")]
      [if( j > 1 ), code:
         {
         [h: someVar = 1]
         [output = strformat("<i>j is big.</i>")]
         };{
         [h: someVar = 0]
         [output = strformat("<i>j is small.</i>")]
         }]
      }]
   [output = strformat("<br>")]
   }]

Same question: Is there any way to work around this?

Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

Re: Nesting limits revisited

Post by Holladerwaldelf »

Well in case of the 'if' the really ugly solution of using the same if-comparison over and over again just came to me, e.g.:

Code: Select all

[for(i,0,2,1), code: 
   {
   [output = strformat("<b>i is %{i}:</b> ")]
   [for(j,0,3,1), code:
      {
      [output = strformat("j is %{j}")]
      [if( j > 1 ): someVar = 1; someVar = 0]
      [if( j > 1 ): output = strformat("<i>j is big.</i>"); output = strformat("<i>j is small.</i>")]
      }]
   [output = strformat("<br>")]
   }]

That will not work for for-loops though...

User avatar
RPTroll
TheBard
Posts: 3148
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Nesting limits revisited

Post by RPTroll »

Check out this wiki entry.

It has a few work arounds.

http://www.lmwcs.com/rptools/wiki/Worki ... ODE_Levels
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
aliasmask
Deity
Posts: 8650
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Nesting limits revisited

Post by aliasmask »

I forget, does the new version increase this limit? I remember something about loops, but I'm not sure about nesting limits.

User avatar
RPTroll
TheBard
Posts: 3148
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Nesting limits revisited

Post by RPTroll »

We have the beginnings of JavaScript which doesn't have the nesting limit but that is still in the early stages of implementation. The next round of development should see that capability grow significantly.

MTSscript still has the 2 deep limitation.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

Re: Nesting limits revisited

Post by Holladerwaldelf »

I am eagerly awaiting the implementation of JavaScript. :D
Is there a time horizon for that?


Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

Re: Nesting limits revisited

Post by Holladerwaldelf »

Any idea when that is planned?

User avatar
wolph42
Deity
Posts: 9830
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Nesting limits revisited

Post by wolph42 »

yup, last friday, then last monday, now... soon(tm).
stuff with sleep deprivation, overwork, crappy internet, etc etc and the fact that we don't have a download page for it yet (as its a new install, it wont be on the current dl page).

Post Reply

Return to “Macros”