[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

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

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

Post by Sydious »

Am I correct in assuming that you can't place a COUNT statement inside another COUNT statement?

I am trying to code a dialog screen that builds a table(grid) with 4 rows of 8 collumns.

The number of cells depends on a var that is from 1 to 32.

I tried using a COUNT(8) inside a COUNT(4) but doesn't seem to work. Is it becuase I am putting the counts inside a count?

Anyone else ever attempt something like this? If so how did you go about it?

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

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

Post by Bone White »

Are you sure it's not because you have more than two nested [wiki]code_(roll_option)[/wiki]?

Roll options which will do an identical (similar?) thing are :

Code: Select all

for(i,1,8), code :{
    code here}


and

Code: Select all

countVar = 0
while (countVar < 8), code :{
    code here
    countVar = countVar+1}

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

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

Post by wolph42 »

Sydious wrote:Am I correct in assuming that you can't place a COUNT statement inside another COUNT statement?

I am trying to code a dialog screen that builds a table(grid) with 4 rows of 8 collumns.

The number of cells depends on a var that is from 1 to 32.

I tried using a COUNT(8) inside a COUNT(4) but doesn't seem to work. Is it becuase I am putting the counts inside a count?

Anyone else ever attempt something like this? If so how did you go about it?


Can you post the code?

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

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

Post by Sydious »

Here is an example of what I think I need to do....Doesn't work.


Code: Select all

[r, COUNT(4, ""):<tr>[r, COUNT(8, ""):<td>"Cell"</td>]</tr>]

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

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

Post by Rumble »

Sydious wrote:Here is an example of what I think I need to do....Doesn't work.


Code: Select all

[r, COUNT(4, ""):<tr>[r, COUNT(8, ""):<td>"Cell"</td>]</tr>]


Nope, won't work. You can't nest roll options like that. What you'd need to do is:

Code: Select all

[r,count(4,""),code:
{
    <tr>[r,count(8,""):"<td>Cell</td>"]</tr>
}]


Roll options must use CODE to nest, as well as adhere to all nesting limits. Basically, unless it's part of a quote-enclosed string, a set of [ ] cannot be inside another set of [ ] without some { } in between.

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

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

Post by Bone White »

Rumble wrote:Roll options must use CODE to nest, as well as adhere to all nesting limits. Basically, unless it's part of a quote-enclosed string, a set of [ ] cannot be inside another set of [ ] without some { } in between.


Because of the code nesting limitation, you'll only be able to put two counts inside each other (three if the last count doesn't contain the code roll option)

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

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

Post by Sydious »

Ok.. So if I were to use...

Code: Select all

[r,count(4,""),code:
{
    <tr>[r,count(8,""):"<td>CELL</td>"]</tr>
}]


Would I be able to replace CELL with and image button?

I tried inputing the following code provided by Ali from a previous post and not getting favorable results.

Code: Select all

[H: inputButton = strformat('<input type="image" src="%s" name="btnMove" value="UP">',getImage("image:Arrow_Up"))]



I replaced CELL with [r: inputButton]

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 »

You can add strings. You dont need to use [r:] more than once to build a single string.

You can either use + or strformat.

Code: Select all

[r, roll(8,""): strformat('<td><input type="image" src="%s" name="btnMove" value="UP"></td>',getImage("image:Arrow_Up"))]

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

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

Post by Sydious »

Ok with your help i have reached this and am successful at createing all the buttons. (with that same image)

Code: Select all

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


<table border = "1">

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

</table>
   


I need to randomize the image on each button. All the images are stored on image:tokens and have the naming convention like image:token_1 thru image:token_32.

If I can't implant code{} in the second count statement, how do I advance a var +1 each time to change the image on each button?

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

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

Post by wolph42 »

You can implement a code statement in the second statement. You can have two nested code levels. If you go beyond that you need to create a user defined function and call that one in your inner statement. Your UDF contains the code with more code statements

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

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

Post by Sydious »

wolph42 wrote:You can implement a code statement in the second statement. You can have two nested code levels. If you go beyond that you need to create a user defined function and call that one in your inner statement. Your UDF contains the code with more code statements


But when I try to put a code statement in like this:

Code: Select all

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


it errors.


User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

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

Post by Bone White »

You can do code :{code :{ [h: statement1][h: statement2] } }

use a count statement like:

firstCount = 1
count 36
if (roll.count / 6) == integer
firstCount = (roll.count / 6) + 1


(you can mix count and if and code statements altogether, to save code nesting)

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 »

I can not test it right where I am now, but I *think*

COUNT uses a special variable roll.count and it is known that on some
occasions this variable gets overwritten. Is it safe to use nested COUNTs at
all?

You can very easily use [wroll]for[/wroll] instead or just use a own index variable for your computations (you have to increment it manually of course).

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

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

Post by Sydious »

wolph42 wrote:?? What's the 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: tokenNameList = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32"] [h: tokenName = "Treasure_Token_1"] [h: button = strformat('

Post Reply

Return to “Macros”