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

How to you reference an attribute of a character you've chosen from a dropdown?

I have a list of character sheets that are NOT tokens I want a macro that lets me choose one of those character from a dropdown and then return a stat of that character What I'm doing is a bit more complicated but this is the boiled down part of what I can't quite figure out. My macro is an ability on my macro character sheet so I can pull it between games. Here's an example of what I'm trying to do: &{template:default} {{name=test}} {{attack=?{foo|1|2|3|4}}} {{str=@{?{foo}|strength}}} So str just returns name_of_character_sheet|chosen_result so "macrosheet|1" Roll20's order of operations seems like it should be able to handle it. And it doesn't seem to be a matter of escaping as that just returns the string literal API's behave on tokens or I run into the same problem. Any help is greatly appreciated! Thank you!
1616575834
Ziechael
Forum Champion
Sheet Author
API Scripter
The order of operations is pretty clear that this doesn't work sadly: Abilities  are expanded (meaning the definition of the ability is placed in the formula anywhere that ability appears; e.g.  %{character name|ability_name}  becomes  /r 1d4 ). Macros  are expanded (e.g.  #macro-name  becomes  /r 1d4 ). Attribute calls  are resolved. (e.g.  @{attribute_name}  becomes  4 ) The 3 above steps are repeated up to 99 levels deep or there are no longer any expansions required. Roll queries  are executed up to 99 levels deep (the player making the roll is asked to provide a value for each query, and that value is substituted in where the roll query appears in the formula). HTML entities within roll queries are parsed once after each roll query (e.g. } becomes }, but } becomes }) By the time the query is resolved the attribute calls have already been made :( You need to consider nesting more in the result of the query like: &{template:default} {{name=test}} {{attack=?{foo|1,1}} {{str=@{1|strength}|2,2}} {{str=@{2|strength}|3,3}} {{str=@{3|strength}|4,4}} {{str=@{4|strength} }}} As you can see it takes some amount of repetition and makes dynamic attribute selection more effort than it is probably worth... the easiest way to do things like that is to use the @{selected or @{target keywords which do require there to be tokens on the page that are linked to journal entries however. &{template:default} {{name=test}} {{attack=@{selected|token_name}}} {{?{Attribute|Str,str=@{selected|strength}|Dex,dex=@{selected|dexterity}} }} etc
Super helpful. Thank you. Seems I was mis-understanding roll query even though it is clearly in the name. What I'm actually trying to do is let a selected token modify an attribute of an NPC that was chosen through the query. The NPC is setup as a character sheet and I'm modifying the stat through the SetChatAttr API. Then I want to report the new value of the queried NPC. Mostly I didn't want all the NPCs on the page cluttering it up. But it sounds like I should have a page in the campaign dedicated to all the tokens involved in this system. And then use selected token, and target token. Is there going to be a timing issue for reporting the resulting stat?
1616593051
Ziechael
Forum Champion
Sheet Author
API Scripter
Ah, yes... make sense and a good solution, I've often used a 'token page' to make mass edits to things in my games. In terms of the reporting of recently changed things it is likely that trying to do it as a single operation will fail to give you the correct report BUT you can likely apply the same method to report and change, for example (not the right syntax for anything but in a meeting so can't go looking right now lol): !chatsetattr --mod str|+1 --ids @{selected|character_id} /em @{selected|character_name}'s strength is now [[@{selected|strength} + 1 ]] I'll reach out for more knowledgeable confirmation for you but the token page is a great idea to avoid clutter.
1616600422
The Aaron
Roll20 Production Team
API Scripter
Ziechael has the right of it.  The thing to remember is that the entire contents of a macro/ability/chat entry are evaluated before being sent to the API.  So his example: !chatsetattr --mod str|+1 --ids @{selected|character_id} /em @{selected|character_name}'s strength is now [[@{selected|strength} + 1 ]] Would become something like this before going to the API: !chatsetattr --mod str|+1 --ids -J1sard23ad423 /em Bob the Slayer's strength is now 17 The API would then pull the attribute named "str" for the character with ID -J1sard23ad423, take it's value of 16 and add 1 to it, then set it back on the attribute. Related is the fact that if the API has any output, it will show up after the /em in the chat as the /em is handled locally, and the API must generate a new message for its output on the API server.
I use a token page also, I call it the anchors.  I have a bunch of "features" in my campaigns that are essentially generic API's utilizing these anchor pages to great effect.  
Seems I understood some of it but not all. I get it now. Thank you! Hopefully I can put this to good use