rol.count doesn't work...anymore

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
User avatar
wolph42
Deity
Posts: 9791
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

rol.count doesn't work...anymore

Post 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.
Last edited by wolph42 on Tue Aug 10, 2010 5:06 am, edited 1 time in total.

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

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

Post 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)

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

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

Post 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.

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

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

Post 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)

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

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

Post 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?

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

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

Post 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....

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

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

Post 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 ...
}]
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

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

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

Post 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

Post Reply

Return to “Macros”