[COUNT(): inside a [COUNT():

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

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [COUNT(): inside a [COUNT():

Post by wolph42 »

CIF might have a point cause I cant find anything wrong with your code. A for(i,1,6), code:{ statement might solve this.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [COUNT(): inside a [COUNT():

Post by CoveredInFish »

In that case you have not posted the actual code. The above sample cannot produce this error :?

The posted sample - for example - wouldnt work inside a [dialog:] tag as that requires a set of braces {} and you can nest those only two levels deep {}.

Nesting limit is for braces {} not for [code:].

Sydious
Giant
Posts: 155
Joined: Sun Aug 21, 2011 2:27 am

Re: [COUNT(): inside a [COUNT():

Post by Sydious »

Here is the code in full with a FOR instead of COUNT

Same error as count.

Code: Select all

[dialog("Treasure Chamber", "width=700; height=650; temporary=1; input=0; noframe=1"):{
<html>
<form>

[h: tokenName = "Treasure_Token_1"]
[h: button = strformat('<td><input type="image" src="%s" name="btnMove" value="UP"></td>',getImage("image:" + tokenName))]


<table border = "1" align = "center" style="background-color:yellow;">

[r,count(6,""),code:
{
<tr>
    [r, for(i,1,6), code: { [r: button] }  ]
</tr>
}]

</table>
</form>
</html>
}]
Throws this error:
   Error in body of roll.       Statement options (if any): dialog("Treasure Chamber", "width=700; height=650; temporary=1; input=0; noframe=1")       Statement Body (first 200 characters): {

[h: tokenName = "Treasure_Token_1"] [h: button = strformat('

',getImage("image:" + tokenName))]

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [COUNT(): inside a [COUNT():

Post by CoveredInFish »

Yep. Thats nesting limit. As said its the number of braces/curly brackets that counts, not the keyword CODE.

Note that you can simply omit a pair here:
This

Code: Select all

[r, for(i,1,6), code: { [r: button] }  ]
does pretty much the same as this

Code: Select all

[r, for(i,1,6, ""): button]

Sydious
Giant
Posts: 155
Joined: Sun Aug 21, 2011 2:27 am

Re: [COUNT(): inside a [COUNT():

Post by Sydious »

CoveredInFish wrote:Yep. Thats nesting limit. As said its the number of braces/curly brackets that counts, not the keyword CODE.

Note that you can simply omit a pair here:
This

Code: Select all

[r, for(i,1,6), code: { [r: button] }  ]
does pretty much the same as this

Code: Select all

[r, for(i,1,6, ""): button]
But then if I omit the code: {} from the FOR I won't be able to add code to +1 to a var to change the image?

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [COUNT(): inside a [COUNT():

Post by CoveredInFish »

Yes.

If you plan to include more code into the inner loop you have to split the macro in two.

The nesting limit is a fact - due to the fact that this macro language is grown into something that was never planned from the beginning - and we have to live with it.

You only have two choices. Either you write the macro within the nesting limit. Sometimes possible, sometimes not. You maybe could - instead of using another variable - use the index variable i of your for-loop. Or you split it into more sub-macros - each macro can nest again two levels of braces. You probably could create some GetButton(index)-user function that you call using the i-variable.

edit: added some case-specific comments.

Sydious
Giant
Posts: 155
Joined: Sun Aug 21, 2011 2:27 am

Re: [COUNT(): inside a [COUNT():

Post by Sydious »

Theres the light bulb. I understand now. I made a openDialog macro to house the Dialog {}s and all came together. Thanks for the help.

User avatar
StarMan
Dragon
Posts: 939
Joined: Mon Jul 18, 2011 1:10 pm
Location: Toronto

Re: [COUNT(): inside a [COUNT():

Post by StarMan »

If you feel it appropriate to make a separate macro call within your innermost code block then you may do so as I sometime do. However, when I really want to keep my code together I work around the nesting limit by using evalMacro.

Your code then becomes:

Code: Select all

[dialog("Treasure Chamber", "width=700; height=650; temporary=1; input=0; noframe=1"):{
<html>
<form>

[h: tokenName = "Treasure_Token_1"]
[h: button = strformat('<td><input type="image" src="%s" name="btnMove" value="UP"></td>',getImage("image:" + tokenName))]


<table border = "1" align = "center" style="background-color:yellow;">

[r,count(6,""),code:
{
<tr>
    [r, for(i,1,6), code: evalMacro('[r: button]')  ]
</tr>
}]

</table>
</form>
</html>
}]
The difference is that you can put more statements after "[r: button]". Generally speaking, I don't put too many as it then starts to look a little silly if you don't align it right.
StarMan - The MacroPolicebox D&D 4E Framework: Import ANYTHING!

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [COUNT(): inside a [COUNT():

Post by CoveredInFish »

Nice trick.

Probably you do omit the code block here (syntax would be wrong anyway):

Code: Select all

<!-- so its not this -->
[r, for(i,1,6), code: evalMacro('[r: button]')  ]

<!-- but this -->
[r, for(i,1,6): evalMacro('[r: button]')]


User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: [COUNT(): inside a [COUNT():

Post by Azhrei »

I wouldn't do this in code that is going to be executed a lot. The function essentially "starts over" and executes the string with a fresh initialization. This is likely to increase the needed stack space and the setup/init is probably slower than just running the code. (If anyone has performance numbers on this I'd love to hear about it.)

However, if you have to do it because of the nesting depth, then the only other option is a separate macro and that has overhead of its own (such as maintenance and functional linkage between macros).

Post Reply

Return to “Macros”