Initiative macro help

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
Xenuite
Cave Troll
Posts: 27
Joined: Sun Nov 08, 2009 8:37 am

Initiative macro help

Post by Xenuite »

I'm currently trying to create a "Roll Initiative" macro for 5th Edition D&D, and I want to take into account that the Barbarian gains advantage on initiative rolls at 7th level.

For reference, I've got class and level stored in a json object so that the key represents the class, and the value is the level in that class, i.e. {"Barbarian":3,"Fighter":1}.

Here's what I have so far:

Code: Select all

[h:addToInitiative()]

[h,if(isPC()==1),code:{
[h,if(json.contains(ClassLevel,"Barbarian")==1&&json.get(ClassLevel,"Barbarian")>=7):Init=2d20k1+Initiative;Init=1d20+Initiative]
};{
[h:Init=1d20+table("Ability Bonuses",Dexterity)]
}]

[h:setInitiative(Init)]

[h:sortInitiative()]
This should check to see if the Barbarian key esists in the ClassLevel object, and then check to see if the value is greater than or equal to 7. If both are true, it should run the true statement, and if not, the false statement.

For some reason, it fails if the Barbarian key doesn't exist, but succeeds if it does, regardless of if the value is 7 or higher.

So, why isn't this working?

Xenuite
Cave Troll
Posts: 27
Joined: Sun Nov 08, 2009 8:37 am

Re: Initiative macro help

Post by Xenuite »

Problem solved. Trying to get the barbarian level from the json object if the key did not exist produced "" which is not a number. When trying to compare it to 7, this breaks the macro, so I had to go a code level deeper.

Code: Select all

[h:addToInitiative()]

[e,if(isPC()==1),code:{
     [e,if(json.contains(ClassLevel,"Barbarian")==1),code:{
          [e,if(json.get(ClassLevel,"Barbarian")>=7):Init=2d20k1+Initiative;Init=1d20+Initiative]
     };{
          [e:Init=1d20+Initiative]
     }]
};{
[e:Init=1d20+table("Ability Bonuses",Dexterity)]
}]

[h:setInitiative(Init)]

[h:sortInitiative()]

Post Reply

Return to “Macros”