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

Storing a Value to an Instance of a Character

I'm currently working on a set of Macros that allows for all players in a game to access mounted weapons on a vehicle and fire them, with accounting for weapons taking multiple actions to load. Currently the way I've got it working is with a simple macro that checks for a custom value, WeaponState, and compares that with the WeaponStatMax. If the WeaponState is less than the WeaponStateMax, increase the WeaponState by 1. If the WeaponState = WeaponStateMax, print a sheetbutton for the Fire macro. As such, a Cannon that takes 2 actions to load would take 3 clicks of the Load Macro to give the button to prompt the Fire Macro (0,1,2).  This works all well and good until I have multiple instances of the same weapon on the same Vehicle, as they would refer to the same WeaponState variable. So, you by loading any  weapon you'd increase the WeaponState for all of them.  Since the goal of this is to properly simulate the Action Economy, this isn't a viable solution. However, I do believe the idea is correct but I'm just implementing it wrong. Two ideas I had were: Treat Bar 2 as the WeaponState variable, so then each one would load independently of the other. Plus, this would give a visual indicator of how far along the load process the weapon is. Use a Status Marker, since you can add a number to each status which would also be independent for each Token. The problem with both is that I don't know how to access the value of either Bar 2 or the Status Marker Value. I know that each character does have a Bar value for each Bar, but that wouldn't be independent per Token. @{selected|bar_2} only pulls this Character-Side value and not the Token-Side one. I'm currently using Scriptcards for the logic side of things. Any ideas as to what I can do to fix this snag would be much appreciated, thanks!
1620568393
The Aaron
Roll20 Production Team
API Scripter
Bar 2 will house a unique value for each token, provided you don't link it to an attribute. It sounds like you've linked it. 
1620568977

Edited 1620569010
It does? Maybe I'm looking at this wrong then. Just to test things, I was trying: !scriptcard {{     --#sourceToken|@{selected|bar_2}     --+Test|[*S:bar_2] }} and !scriptcard {{     --+Test|@{selected|bar_2}     }} For the first I was getting 'undefined' and for the second I was getting 'selected|bar_2'. I had set the bar_2 value to '3'.
1620577220
timmaugh
Forum Champion
API Scripter
Don't use @{selected|bar_2}... that isn't a thing. (When you see that, it's kicking it back to you as text.) You want @{selected|bar2}. =D
1620579093
The Aaron
Roll20 Production Team
API Scripter
Also, make sure you're only selecting one token when you do that. If you select two or more, it's not going to be obvious which selected token's bar 2 you're getting. 
Yep that did it! I always have trouble remembering where the _'s go in these variables sometimes ;-; That's a good point, I'll have to remember that for the future when I start trying to make AOEs, the Aaron! Thanks for much for the help, both of you! : D
1620687709

Edited 1620687753
Update: I got this to work before my session started, but of course now it isn't working. What's happening is this: The bar2 value is getting increased by 1, but the bar2 value on the token remains at 0. My conditional is failing because of this discrepancy, since what it's seeing is a 0. Here's the output:  And the code: !scriptcard {{ --#title|Vehicle Weapon Action --#sourceToken|@{selected|token_id}         --+WeaponStateMax|@{selected|WeaponStateMax}         --+Bar 2|@{selected|bar2} --? @{selected|bar2} -lt @{selected|WeaponStateMax}|Load --? @{selected|bar2} -ge @{selected|WeaponStateMax}|Fire --X| --:Load| --@modattr| _sel _bar2|1 --+Action|@{selected|character_name} is loading... --X| --:Fire| --+Fire|[sheetbutton]Click Here::[*S:character_id]::Fire[/sheetbutton] --@setattr| _charid [*S:character_id] _bar2|0 _silent --X }} This has got me quite stumped, so any help is appreciated, thanks!
1620701204
timmaugh
Forum Champion
API Scripter
bar2 is a facet of the token, not the character... If the bar you want to modify is linked to an attribute on the character, then you can use ChatSetAttr to modify the appropriate attribute (not "bar2"). If the bar is NOT linked to an attribute, then you want to use TokenMod to make the change to the token.
Oh, good to know! I'd not realized that you could set bar values with TokenMod or that ChatSetAttr only worked for Attributes, thanks!