Problem with macro

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
wyrmwood_lives
Cave Troll
Posts: 25
Joined: Fri Nov 08, 2019 10:22 pm

Problem with macro

Post by wyrmwood_lives »

Hi all,

Been playing with this for a couple of hours now, and it is working as intended. When I switched from an encounter map to a larger dungeon map, simply adding all the tokens wasn't good enough. I wanted to be able to selectively add tokens, and have it retain the original initiative for all currently in the initiative panel. This allows me to add creatures not yet in the encounter to the encounter, and when the players' turns come up, they get to "roll". (Although I have to be careful to have the chat window visible at the time or they have to tell me over voice.)

Code: Select all

[h, foreach(tid, getSelected()), code: {
    [switchToken(tid)]
    [addToInitiative()]
}]
[h: tokens = json.get(getInitiativeList(), 'tokens')]
[h, foreach (token, tokens, ''), code: {
    [tid = json.get(token, 'tokenId')]
    [switchToken(tid)]
    [if (getInitiative() == 'null'), code: {
        [init = (if(Init == '', 0, Init))]
        [if (isNPC(tid)), code: {
            [setInitiative(1d20 + init + init/10 + d100/1000)]
        };{
            input('roll')
            [setInitiative(roll + init + init/10 + d100/1000)]
        }]
    };{}]
    [broadcast(getName(tid) +' init: ' + getInitiative(), 'gm')]
}]
[h: sortInitiative()]
However, after debugging it, I wanted to remove the broadcast, but if I do, I get
   Error in body of roll.       Statement options (if any): h, foreach (token, tokens, ''), code       Statement Body (first 200 characters): { [h: tid = json.get(token, 'tokenId')] [h: switchToken(tid)] [h, if (getInitiative() == 'null'), code: { [h: init = (if(Init == '', 0, Init))] [h, if (isNPC(tid)), code:
I must be missing something obvious. I've gone through and checked all the brackets, braces and parens, but maybe someone can enlighten me?

Here's what it looks like without the broadcast:

Code: Select all

[h, foreach(tid, getSelected()), code: {
    [switchToken(tid)]
    [addToInitiative()]
}]
[h: tokens = json.get(getInitiativeList(), 'tokens')]
[h, foreach (token, tokens, ''), code: {
    [tid = json.get(token, 'tokenId')]
    [switchToken(tid)]
    [if (getInitiative() == 'null'), code: {
        [init = (if(Init == '', 0, Init))]
        [if (isNPC(tid)), code: {
            [setInitiative(1d20 + init + init/10 + d100/1000)]
        };{
            input('roll')
            [setInitiative(roll + init + init/10 + d100/1000)]
        }]
    };{}]
}]
[h: sortInitiative()]

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with macro

Post by aliasmask »

You problem is that you have too many nested {}'s. Try this:

Code: Select all

[h, foreach(tid, getSelected()), code: {
    [switchToken(tid)]
    [addToInitiative()]
}]
[h: tokens = json.get(getInitiativeList(), 'tokens')]
[h, foreach (token, tokens, ''), code: {
    [tid = json.get(token, 'tokenId')]
    [switchToken(tid)]
    [if (getInitiative() == 'null'), code: {
        [init = if(Init == '', 0, Init)]
        [roll = 1d20]
        [if(isPC()): input("roll")]
        [setInitiative(roll + init + init/10 + d100/1000)]
    };{}]
}]
[h: sortInitiative()]

User avatar
wyrmwood_lives
Cave Troll
Posts: 25
Joined: Fri Nov 08, 2019 10:22 pm

Re: Problem with macro

Post by wyrmwood_lives »

Works perfect, thanks! I'm still scratching my head about how it worked with the extra broadcast statement, but cheers for sorting me out! So 2 is OK, but 3 is too many?

Post Reply

Return to “Macros”