Page 1 of 2

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

Posted: Mon Sep 26, 2011 1:43 pm
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?

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

Posted: Mon Sep 26, 2011 1:57 pm
by Bone White
Are you sure it's not because you have more than two nested code_(roll_option)?

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}

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

Posted: Mon Sep 26, 2011 2:16 pm
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?

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

Posted: Mon Sep 26, 2011 2:53 pm
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>]

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

Posted: Mon Sep 26, 2011 2:55 pm
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.

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

Posted: Mon Sep 26, 2011 5:19 pm
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)

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

Posted: Mon Sep 26, 2011 11:18 pm
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]

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

Posted: Tue Sep 27, 2011 3:56 am
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"))]

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

Posted: Thu Sep 29, 2011 3:55 pm
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?

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

Posted: Thu Sep 29, 2011 4:22 pm
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

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

Posted: Thu Sep 29, 2011 4:26 pm
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.

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

Posted: Thu Sep 29, 2011 4:30 pm
by wolph42
?? What's the error?

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

Posted: Thu Sep 29, 2011 4:31 pm
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)

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

Posted: Thu Sep 29, 2011 4:33 pm
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 [for:] instead or just use a own index variable for your computations (you have to increment it manually of course).

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

Posted: Thu Sep 29, 2011 4:35 pm
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('