Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] How to get first Global attack (damage,ac,save-throw,skill) Modifier?

Im learning programming an API and I trying to get the first Global Damage (and Attack) Modifier and enable them.

I know that exists an API called ChatSetAttr, but I learning and I want do simplest code.

I found in another threads that has 2 attrs:

repeating_tohitmod_$0_global_attack_active_flag

repeating_damagemod_$0_global_damage_active_flag

Bug I can't access them with:

```

    let test1 = findObjs({name: 'repeating_tohitmod_$0_global_attack_active_flag'});

    let test2 = findObjs({name: 'repeating_damagemod_$0_global_damage_active_flag});

```

I tried to passing characterId and other keys, but always return empty array.

April 15 (4 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

The actual names will use an ID instead of the relative reference of $X. Essentially in macros you can refer to repeating attributes two ways. Either by their relative position in the list (the $X syntax), or by their ID. But the attributes' actual names use their IDs. So you need to do a findObjs on all attributes belonging to the character and then filter them for attributes that match your name criteria. Something like:

//assuming you've gotten a character's id somehow previuosly in the script and named it character
let attributes = findObjs({type:"attribute",characterid:character.id});//gets all the character's attributes
attributes = attributes.filter((a)=>/global_(?:attack|damage)_active_flag$/.test(a.get('name')));//filters them for attributes whose names end with global_attack_active_flag or global_damage_active_flag

Hope that helps

Thank you! You helped me a lot!