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

bar2_max keeps getting set to 11223344 from the long string I set it to when the bar is linked to a character value

1452763480
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am trying to code a custom menu for each token. Version 1 of my character sheet stored an amount of information about status's on the character sheet. That was fine for characters, but not adequate for Mooks. There was no way to say (for example) Mooks 1 and 3 are aggressively attacking (and get certain bonus's or penalties to dice rolls) but the other mooks are not.  So I am now upgrading the sheets to instead of storing this on the character sheet, it is to instead store this information on the token. I am using status markers to store this information. So for example, when the the Sentry gun is being displayed, the character is aggressively attacking and gets plus three to attacks, but minus 3 to defenses. All good so far, but many of the conditions are a poor match for any of the available icons, so it is difficult for new players to know which symbols match which conditions. Therefore I want a custom menu for each token that when a specific token action is selected, a popup menu appears with a dropdown list that allows the user to select to turn certain options on, and lists the ones that are already on and allow them to be turned off.  So for example if the character is already aggressively attacking, the option would be "Aggressive Attack: Off".  What I am doing is storing the menu is bar2_max. I am using the other 5 bar values for more conventional things, but was not previously using bar2_max for anything useful. I now store the custom menu in bar2_max, and have the macro retrieve it as follows. !edParse~ Status: ?{@{selected|bar2|max}} So that works as well, no problems. Where I have a problem is that it only works if I DON'T have bar2_link set. I want bar2_value set to @{Wounds} Until I have bar2 linked, I can have my super long menu string in bar2 max. As soon as I link it, it changes to 11223344. I can change it to short values, but I can not change it to long values anymore.  I can't figure out why this would make a difference. I could see it if it did not work at all. But can't figure out why it only fails if the attribute is linked.  So question number one is, can anybody tell me what is going on. question number two is, can anybody suggest a place to store information linked to a token (not a character).  Thanks.
1455832532
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I would still love an answer to this.
1455883648
The Aaron
Roll20 Production Team
API Scripter
(Moved to API)
1455884216
The Aaron
Pro
API Scripter
I'm sorry I missed this before, I tend to skim Specific Use Questions but read API deeply.  Regarding why the max value gets changed to a shorter value, I'd need to test to get a good answer but I'm sure it has to do with suddenly being tied to the max field of the attribute along with all the other mooks. Since an attribute contains both a current and max value, there isn't a way to tie only the current value to and attribute and leave the max unlinked. Probably some token had that value in its max, or maybe the text you have in there just gets compiled down to that value. Hard to say.  As to what you can do instead, I'd either store the token specific details in the state or reconstruct them for the statusmarkers it the menu is deterministic based on what is set.  (I'll come back with some code once I'm on my computer.)
1455889190
The Aaron
Pro
API Scripter
Ok, here's a short snippet of code that demonstrates the state.  Be mindful that the state is a shared object.  The only thing you should put as a root property of state is some object to hold all your things. on('ready',function(){     "use strict";     // If there isn't a state.chris, create it as an object with the property tokens containing an object     if(!_.has(state,'chris')){         state.chris={             tokens: {}         };     }     // create an event handler that fires when status markers are changed     on('change:graphic:statusmarkers',function(obj){         // something for that token         state.chris.tokens[obj.id]="Has Statuses: "+obj.get('statusmarkers');     });     // create an event handler that fires on chat messages     on('chat:message',function(msg){         var match=msg.content.match(/^!test/);         if (msg.type !== "api") {             return;         }         // if the message starts with !test         if(match && msg.selected){             // for each of the selected tokens             _.each(msg.selected,function(o){                 // if we have recorded something for it in state.chris.tokens                 if(_.has(state.chris.tokens,o._id)){                     // send what we recorded to the chat                     sendChat('','/w "'+msg.who+'" '+state.chris.tokens[o._id]);                 }             });         }     }); }); With this script installed, change some statuses on a token then run the command: !test
1455938505
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Thanks for the answer, but I am afraid you solved the wrong problem! The reason I stored it in bar2_max is that bar2_max can be accessed by a macro as @{selected|bar2|max} State can't be accessed by a macro. Let me explain better what I am trying to do. If I store something like this... Status|Agressive Attack,Agressive|Called Shot : Off,Called:Off|Defensive Stance,Defensive|Split Movement,Split|Tail Attack,Tail|Blindsided,Blindsided|Knocked Down, Knocked|Range Long, Range|Surprised, Surprised|Reserved Action, Reserved|Cover None|Cover Partial|Cover Full|Not Harried|Harried|Overwelmed x1,OW1|Overwelmed x2,OW2|Overwelmed x3,OW3|Overwelmed x4,OW4|Movement OK,MoveOK|Movement Impaired Partial, MovePart|Movement Impaired Full, MoveFull|Vision OK,VisionOK| Vision Impaired Partial, VisionPartial|Vision Impaired Full, VisionFull|Health OK, HealthOK |Health Unconscious, HealthUnc|Health Dead, HealthDead in bar2_max, then this !edParse~ Status: ?{@{selected|bar2|max}} will take the above long string and use it in a pop-up query with a drop down list, and then send the selected result to the API. Note that the above has already been customized (Called Shot is ready to be toggled to Off, most other things are ready to be toggled On).  So the result is that if somebody presses the "STATUS" token action, a custom menu for that token instantly appears.  Now I think that with your method I can make it so that if somebody presses the "STATUS" token action, I can have the API create a custom menu button in the chat window that the user could press to have the custom menu appear, but as far as I know, it can't just make the popup menu appear in one step.  Another solution would be to simply not link bar2. bar2 will not be linked for Mooks anyway, it is only Characters that I want to have Wounds on the character sheet match bar2.  Now I suppose I could have   on('change:graphic:bar2_value',function(obj){ Which will allow me to change wounds when bar2 changes. But unless I am mistaken, while sheetworkers can be triggered whenever Wounds changes, there is no way that they can force a change to bar2. And I know of no way for the API when wounds changes except to listen to on change attributes and simply ignore every attribute that is not Wounds, and that seems excessively wasteful. (Is that too wasteful?) So we run the risk of bar2 and wounds getting out of sync with each other.  I would appreciate any other ideas, or ways to do some of the ideas above. 
1455939862
The Aaron
Pro
API Scripter
That does make more sense now. Is the 11223344 only happening on characters or does it happen on mooks too?  When you link the bar to the attribute, the current and max value get replaced by whatever the current and max of the linked attribute are. Have you tried updating the max of the attribute to have your menu on characters?
1455940434
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
My previous message was about how I am thinking about working around this bug/problem. However I still find the problem itself very interesting. Here is how to duplicate it. Take a character sheet and put three values on it.         <input name="attr_a" type="text"/>         <input name="attr_b" type="text"/>         <input name="attr_b_max" type="text"/> Note: I have also tried this with type="number" identical results. Save the character sheet. Open a VTT. Create a Token.  For each of bar1, bar2, and bar3, put some number in value, and in max put a very long string such as  Status|Agressive Attack,Agressive|Called Shot : Off,Called:Off|Defensive Stance,Defensive|Split Movement,Split|Tail Attack,Tail|Blindsided,Blindsided|Knocked Down, Knocked|Range Long, Range|Surprised, Surprised|Reserved Action, Reserved|Cover None|Cover Partial|Cover Full|Not Harried|Harried|Overwelmed x1,OW1|Overwelmed x2,OW2|Overwelmed x3,OW3|Overwelmed x4,OW4|Movement OK,MoveOK|Movement Impaired Partial, MovePart|Movement Impaired Full, MoveFull|Vision OK,VisionOK| Vision Impaired Partial, VisionPartial|Vision Impaired Full, VisionFull|Health OK, HealthOK |Health Unconscious, HealthUnc|Health Dead, HealthDead Note that this value will stay in all three Max's and all seems OK, no problems.  Now go into token setup and link bar1 to a and bar2 to b. The values and max values in a and b both go away (even though the character sheet does not have a a_max defined). Enter/change values on ether the character sheet and the bubbles, everything seems linked and working fine.  Go into the gear tab of your token and copy the long string into bar1_max. It seems to be OK, it likes it. However if you click OK and then reopen this, bar1 max now has a value of 11223344. Attributes and abilities also has a_max having been changed to 112233 go to the character sheet, copy the long string into b_max on the character sheet. It displays nicely and seems to be OK. Go to the gear icon of the token, and it says that bar2_max (linked to b_max) is 11223344. Refresh the browser just to force things to reload. Bar2_max is still 11223344.    b_max is still the very long string. Attributes and abilities still has the very long string displaying there. The token still has 11223344 During all this time, the value in bar3_max that has never been linked is fine.  By the by, the bar is also wacked, since it wants to display a huge bar. Conclusion: If you put a very long string into barX_max, and the bar is linked it changes it to 11223344. If you put it into the character sheet or attributes and abilities, it works fine, but puts a 11223344 into barX_max, so it is not linked right, since bar2_max and b_max are reporting different values. Any idea why it would do this?  Like I said, I have some ideas for work arounds, I am just wondering why it would do this bizarre thing. Thanks
1455940985

Edited 1455941115
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Nope, no problems on Mooks, because I don't link them. I only link the characters, and the problem only occurs when the bars are linked. And like I said, I think I can pseudo-link characters with the API - so probably have a work around. More information. If you have a character open to see the attributes and abilites, and have the token edit open, and copy the long string to the token max, the attributes and abilities update to the long string as soon as you click save on the character. Then when you go in a 2nd time you see that it has been changed to 11223344.  If you then click save on the character rather than cancel, that is when it will copy 11223344 to the attributes and abilities overwriting the long string.  I have not tested how "long" of a string it takes to get this behaviour. I will do that next. 
1455942238

Edited 1455942599
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Game changer here. Ignore much of what I said, it has nothing to do with the length of the string. It has everything to do with the contents of the string. Specifically, I get 11223344 whenever the string contains the following segment.  Overwelmed x1,OW1|Overwelmed x2,OW2|Overwelmed x3,OW3|Overwelmed x4,OW4 Specifically, if the string HAS NO DIGITS, the string is fine. If it has ANY DIGITS, everything except the digits are removed. And once again, only if they are linked, and it does not matter if they are linked to a number or a text field or is a max field of a number that has no max in the document.  And I might add that if there are no digits, the bar is blank, which is what I want in this specific case anyway. With digits 1123344 you get a bar way the heck across. So now I kind of know why it is doing that, which is what was driving me crazy. 
1455944003
The Aaron
Pro
API Scripter
Wow!  Good find. So are you thinking about manually keeping barX current and the attribute value in sync?
1455944157

Edited 1455949955
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am thinking of just taking the digits out of my menu    Overwelmed IV    should work just as well as Overwelmed 4 Thank you very much!!!