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

Can I use ChatSetAttr to set an attribute using the Token_id

I am trying to create a macro that will allow my PF2e Investigator to grant the +1 bonus to all characters within his active Empyreal Blessing aura but am stuck. I have an array of all the token-ids on the page and I have successfully calculated the distance from the source and compare it to my current aura radius.  I have been able to cycle through all tokens and assign them a status marker to provide a visual reminder that it is on using token-mod. I'm now trying to modify the _query_roll_bonus by setting it to 1 for all toons within my current aura.  Unfortunately, I believe I have token-ids in my array and I cannot seem to reference the attribute for each character.  I'm getting this error: This is the code as it exists now: !scriptcards {{   --#sourceToken|@{selected|token_id}   --@token-mod|_ids [*s:t-id] _set aura1_radius|+5   --#emoteText|[*S:character_name] summons the powers of his ancestors to aid in battle   --+|[b][c]Blessings from beyond help your companions strike true. You and your allies gain a +1 status bonus to attack rolls while within the emanation.[/c][/b]  --+|Increment Aura 1 radius and get current radius  --=RadiusAura1|[*S:t-aura1_radius]+5  --+|Aura 1 Radius = [$RadiusAura1] ft    --+|Collect array of all players  --~dummy|array;pagetokens;PC_array;@{selected|token_id}  --~count|array;getcount;PC_array  --+Total:|There are [&count] graphical objects on the page  --+|Loop through each PC  --%loopCounter|0;[&count]    --+Value|[[@PC_array([&loopCounter])]:character_name]    --+|Calculate the distance of [@PC_array([&loopCounter])] from source token    --~Aura1Range|distance;@{selected|token_id};[@PC_array([&loopCounter])]    --=FeetApart|[$Aura1Range] * 5    --+|The distance = [$FeetApart]    --?[$FeetApart] -le [$RadiusAura1] |[       --@setattr| _silent _charid [@PC_array([&loopCounter])] _query_roll_bonus|1       --@token-mod|_ids [@PC_array([&loopCounter])] _set statusmarkers|!trophy    --]|    --+|If Distance > Radius Aura turn off Hit bonus and turn off trophy flag  --%|  --+Loop|Is Done! }} Can someone point me in a direction?  I tried using --charid in ChatSetAttr but I don't think it does what I thought....
1713458486

Edited 1713458536
Since you are using ScriptCards already, that mod can alter the character directly.  Replace your ChatSetAttr command line with: --!a:[* [@PC_array([&loopCounter])]:character_id]|! query_roll_bonus:1 That should create the attribute if it doesn't exist yet as well as set it to 1. 
Since I agree with Erik about using ScriptCards object modification  instead of ChatSetAttr. I wanted to mention something else about your post. You have these two line: --~dummy|array;pagetokens;PC_array;@{selected|token_id} --~count|array;getcount;PC_array I just wanted to point out 2 things. First, I see you mention PC, as in loop through each PC but you aren't including a filter on your array;pagetokens function, so you will get every single graphic object on the page, not just PC objects. There are filters you can use, like `npc` and `pc` or `char`, to narrow that search. And second, that array;pagetokens function already returns the count of the tokens returned. [&dummy] would have the number of tokens returned. You don't need another function to get the count. Creates an array (arrayname) of all of the token ids (technically Graphics objects) on the same page as the specified token id or on the page matching the page id. Returns the number of tokens found to the stringVariable. Available optional filters are : all, char, graphic, pc, npc. The filters will return only those tokens that match that criteria (char means tokens have a "represents", graphic doesn't. pc indicates a represents token has a controlledby, npc doesn't.) Also if you just want to loop through the array, you might want a foreach loop . You can access array items with the loop iterator like so: --~pcCount|array;pagetokens;PCTokenArray;[*S:t-id];pc --%pcTokenID|foreach;PCTokenArray --+TokenID|[&pcTokenID] is the token id for [*[&pcTokenID]:t-name] --%| Just wanted to point out a couple things that you might find easier to use in the future. Nothing wrong with iterating over an array with a for loop. Lots of ways to accomplish the same thing, I just think the foreach loop tends to be simpler and more readable for many folks.
Gentlemen - Both of you- Thank you for your response and guidance.  Your help allowed me to create exactly what I wanted.  You are both geniuses and I will tell my children of your exploits.