Page 1 of 1

rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 4:40 am
by wolph42
Can anyone explain to me why roll.count all of a sudden doesn't work anymore in this routine (I haven't touched it since the last time it did work:

Code: Select all

<!--Output extra hit locations for Full Auto Burst-->
[
r,if(extraShotsFullAuto > 0), count(extraShotsFullAuto), CODE: {
    <!--Calculate damage-->
    [h:getDamage(wpnUsed,govChar,allowRighteousFury)]    
    
[h:output = macro.return]
    [h:damage.json = json.get(output,2)]
    <!--create damage tooltip-->
    [h:TTDamage = formatTooltip(damage.json)]
[
h:check = roll.count+1]
[
h:pause("check")]
    [r:"<b>"+table(extraTable, roll.count+1)+"</b> (<b>"+TTDamage+"</b> dmg)"]
    [h:fury = max(fury,json.get(output,0))]
};{}]
 

edit, I've simplified the code, same 'error':
[spoiler=simple]

Code: Select all

[r, count(extraShots), CODE:{
    <!--Calculate damage-->
    [h:getDamage(wpnUsed,govChar,allowRighteousFury)]    
    
[h:output = macro.return]
    [h:damage.json = json.get(output,2)]
    <!--create damage tooltip-->
    [h:TTDamage = formatTooltip(damage.json)]
    <!--calculate damage-->
    [h:damage =  formatTooltip(damage.json,2)]
    <!--retrieve location-->
    [h:location = table(extraTable, i)]
    [i=i+1]
    <!--text output to chat-->
    [r:"<b>"+location+"</b> (<b>"+TTDamage+"</b> dmg)"]
    [h:fury = max(fury,listget(macro.return,0))]

[
h:bla=roll.count]
[
h:pause("bla")]
}]
 
[/spoiler]
the debug gives as output (in case of 4 extra shots): 2,2,2,2
Last session I ran this (b63) it still worked and now all of a sudden it doesn't. I did try the standard: [COUNT(5, "<br>"): "This is roll " + roll.count] and that does work.

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 4:48 am
by CoveredInFish
I had the idea that the combination of IF and COUNT in one roll option might be a problem but

Code: Select all

[r, count(5), if(1d2==1): roll.count; "-"]

worked fine here (b70)

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 4:57 am
by aliasmask
I think CiF is right and it's that combination of if,count. Personally, I would just use a for loop where for(i,0,extraShotsFullAuto) where the if isn't even needed.

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 5:06 am
by wolph42
i've edited the first post with a simpler version, its NOT the problem....

And thnx for the for statement, I should have thought of that. Still Im curious to why this doesn't work
btw should it not be for(i,1,extrashots) edit: never mind .. it should be for(i,1,extrashots+1)

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 10:49 am
by Azhrei
wolph42 wrote:Last session I ran this (b63) it still worked and now all of a sudden it doesn't. I did try the standard: [COUNT(5, "<br>"): "This is roll " + roll.count] and that does work.

Do those UDFs define their own scope? If they don't, they could be affecting the value of roll.count, couldn't they?

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 11:04 am
by wolph42
Azhrei wrote:
wolph42 wrote:Last session I ran this (b63) it still worked and now all of a sudden it doesn't. I did try the standard: [COUNT(5, "<br>"): "This is roll " + roll.count] and that does work.

Do those UDFs define their own scope? If they don't, they could be affecting the value of roll.count, couldn't they?


hmm interesting point, with 'own scope' do you mean specifically a 'count' function or do other loops also interfere?
I have changed the other UDF's since the last time so it may indeed be that. I'm not sure though there is a 'count' function in one of them, but I have to check to be sure.
Interesting notion none the less, cause this is something I would never have guessed....

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 11:45 am
by biodude
The formatToolTip UDF does use FOREACH loops. All loops ([wroll]count[/wroll], [wroll]for[/wroll], [wroll]foreach[/wroll], and even [wroll]while[/wroll]) generate their own roll.count, if I recall correctly. Therefore, if you defined the formatToolTip function with the same variable scope (4th argument in [wfunc]defineFunction[/wfunc]: refers to the scope of variables within the UDF when it is called), then every time you call formatToolTip, it will reset the value of roll.count. If roll.count is a global variable, it might do it anyway. I'm not sure.

I avoid using COUNT as much as possible, partly because I read somewhere that FOREACH is faster, and besides I prefer to keep my loop counting variables organized and separate in case of nesting. In your case, I would recommend using FOR or FOREACH instead. If you are determined to stick with COUNT, use a variable other than roll.count to track iterations, to avoid conflicts with nested loops & UDFs:

Code: Select all

[H: i = 0 ]
[H, COUNT( num ), CODE:{
    [ i = i+1 ]
    ... more code ...
}]
<!-- Or just use a FOR loop -->
[H, FOR( i , 1 , num ), CODE:{
    ... code to loop through ...
}]

Re: rol.count doesn't work...anymore

Posted: Tue Aug 10, 2010 1:44 pm
by wolph42
i already changed the loop with a for loop, i just was curious why all of a sudden the roll.count didn't work anymore. But this explains a lot. thnx for the heads-up