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

Further scriptcard question regarding calling chatsetattr

Thanks for your answer to my earlier question, it's working fine, what I'd like to do now is add a bit to apply damage to the stats of a wounded character.  I have this in the Been-Hit macro !script {{ --#title|@{selected|token_name} has been hit --#leftsub|[[1t[Been-Hit]]] --#sourceToken|@{selected|token_id} }} I want to, as a last step, I have ChatSetAttr and SelectManager mods installed, they seemed to be what I needed, I want to add something like !setattr --sel --Legs|-1
So for that you don't actually need ChatSetAttr, ScriptCards can modify attributes itself.  ScriptCards wiki link on Object_Modification So in the below example it assumes you want to roll on a table to get the location, all of those table entries are character attributes, and that you will always subtract 1 from the attribute. If these assumptions are not correct, let me know, they can be changed. !script {{ --/|VARIABLES TO SET --&LocationTableName|Been-Hit --#sourceToken|@{selected|token_id} --=LocationRoll|[T#[&LocationTableName]] --:ModifyAttribute| --!a:[*S:character_id]|[$LocationRoll.tableEntryText]:-=1 --:DisplayResults| --#title|[*S:t-name] has been hit --#leftsub|Location:[$LocationRoll.tableEntryText] --+[*S:t-name]|got hit in the [$LocationRoll.tableEntryText] and has [*S:[$LocationRoll.tableEntryText]] remaining }} So this sets a String Variable  for the table name to roll on Sets the sourceToken parameter Uses a Roll Variable to roll on the table Uses the ScriptCards object modification `--!` to modify an attribute `a` for the source token character_id `[*S:character_id]` with the attribute set at the table text and reduces it by 1 Then it will display the results with the #title and #leftsub parameters and a short blurb about the location and its remaining value after modifications That's what the example script shows. Let me know if you have any questions about this. If you prefer to all out to other Mods then ScriptCards can do that as well with --@  where the parameters go after a pipe | and double-dashes `--` are replaced with underscores `_`. Note that Mod calls are asynchronous which means that the currently running ScriptCard won't be able to return any values from after the Mod has run, so you wouldn't get the updated value without also doing some calculations in the ScriptCard.
Thanks Joshua, just the info I needed, good that it can all be done within scriptcard. I'll need to tweak the contents of the been-hit table, but, that's not a problem, unless it's possible for the card to extract the attribute from the table text which will always be in the form Legs - Only one Move per turn Arms - Only one Shoot per turn etc. i.e. the attribute will always be first on the line. This would be a very nice to have, but, not essential Thanks again for your help.
Should be possible. Assuming the location attribute is always before the dash -, then can just parse that out of the table text. I'll post an updated example shortly. As long as each entry has a consistent format, that makes things much easier so let me know if that's not the case but I'm assuming it would be in the format of: Location - Effect
!script {{ --/|VARIABLES TO SET --&LocationTableName|Been-Hit --#sourceToken|@{selected|token_id} --=LocationRoll|[T#[&LocationTableName]] --/|Parse Location Text for Attribute --/|Table Entries are assumed to be in the format of AttributeName - Effect --~LocationAttribute|string;before;-;[$LocationRoll.tableEntryText] --~LocationAttribute|string;trim;[&LocationAttribute] --:ModifyAttribute| --!a:[*S:character_id]|[&LocationAttribute]:-=1 --:DisplayResults| --#title|[*S:t-name] has been hit --#leftsub|Location:[$LocationRoll.tableEntryText] --+[*S:t-name]|got hit in the [&LocationAttribute] and has [*S:[&LocationAttribute]] remaining }} So in this example it uses two  String functions , before and trim to grab everything in the table entry text before the dash `-` and then trims any whitespace and sets that to a String variable named LocationAttribute. That String variable is then used in the object modification call and in the Display Results output. Hope that helps. Let me know if you have any other questions.
1707065043

Edited 1707065278
Absolutely spot on! works brilliantly Really appreciate your help.