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

Calling TokenMod from a legacy charseet in a legacy engine game

1752737763

Edited 1752738037
StéphaneD
Pro
Sheet Author
API Scripter
Hi I have posted this in the [Script Update] thread for TokenMod but apparently it was not the right spot as I got little attention, so here I go again. Actually it looks like an issue with the legacy game engine so I'm afraid it won't be resolved anytime soon, but I thought I'd pass my observations along I am implementing interactions between the sheet I am developing (for an heroic fantasy french game system) and TokenMod. This is all legacy game & sheet (no JG, no Beacon) Whenever a condition (blinded, restrained, etc...) is set or unset on the sheet, I have the condition effects sent to chat, some debuffs applied on various attributes if required, and a token-mod command sent to chat via the CRP functions (startRoll & finishRoll) to set/unset token markers What I am seeing : - If the condition implies a debuff on an attribute  linked to a token bar  (namely the Defense attribute, same as AC for D&D or Evasion for Daggerheart), the condition marker is actually displayed on the token only once in two. Set condition : marker added Unset condition : marker removed Set condition : no marker added (visually, I haven't tried to check the VTT objects) Unset condition : no visual change Set condition : marker added etc... - If the condition does not imply any debuff on the Defense attribute, or if the Defense attribute is not linked to a token bar, then the condition marker is displayed or removed as intended each time the condition is set or unset Here are the token-mod commands that are sent to set and unset a condition marker !token-mod --ignore-selected --ids @{Kamshaka|character_id} --set statusmarkers|+cof2-aveugle !token-mod --ignore-selected --ids @{Kamshaka|character_id} --set statusmarkers|-cof2-aveugle Again, I don't think that is an issue with TokenMod, but since The Aaron is now a member of the Roll20 team, maybe he can get the attention of whoever still works on the legacy engine and not JG or Beacon NOTE : I've tried with the ! flag in front of the marker instead of + or - , but still no joy
1752782296
timmaugh
Forum Champion
API Scripter
OK, I have tried these commands just using TokenMod, and they work just fine... so something has to be gummed up in the CRP integration. The fact that you get the statusmarker half of the time does seem to complicate troubleshooting... but here are some things to try. 1) Look at the --api-as parameter for TokenMod; it could be that you need to specify a player id for the command to work (again, not sure about this one because it does happen every other time) 2) If you install the Metascript Toolbox script, you will be able to test a few things from the chat. When you get to the point in the cycle where you don't have a statusmarker on the token and you think you *should*... run a command like: !@(Kamshaka.is.cof2-aveugle){&simple} You should see that report "yes" in chat if the token bears the "cof2-aveugle" statusmarker, and "no" if it does not. This will let you at least judge whether the token is there without the VTT updating the display to show it to you. 3) The next thing to look at is whether the commands are being sent to TokenMod at all. You can do this by setting up a logging statement in TokenMod, or you can use something like this scriptlet to generate logging messages: /* */ var API_Meta = API_Meta || {}; API_Meta.Log = { offset: Number.MAX_SAFE_INTEGER, lineCount: -1 }; { try { throw new Error(''); } catch (e) { API_Meta.Log.offset = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - (4)); } } on('ready', () => {     logAll = true;     on ('chat:message',msg => {         if(msg.type === 'api' && /^!logall(\+|-)/.test(msg.content)) { logAll = /logall\+/.test(msg.content); log(`logAll is ${logAll}`);}         if (!logAll) {             if(msg.type !== 'api' || !/^!log\s.*/.test(msg.content)) { return; }         }         log(JSON.stringify(msg,undefined,2));     }); }); { try { throw new Error(''); } catch (e) { API_Meta.Log.lineCount = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - API_Meta.Log.offset); } } /* */ I've set it to already by "on" by default (logging every message to the script log panel), but you can turn that off. Manage the "logAll" setting by running either of: !logall+ !logall- ...to turn "logAll" on or off, respectively. Even if "logAll" is "false" or "off", you can still log a message just by prepending it with "!log"... that could be a way to test the structure of a message without it actually hitting your intended recipient script (ie, TokenMod). My guess is that this will likely owe to CRP not performing as expected in some way, but you can narrow it down to be sure that's what's going. That will help Aaron (or other Roll20 peeps) to focus on where the actual issue is.
1752819746

Edited 1752819938
StéphaneD
Pro
Sheet Author
API Scripter
Hi timmaugh Thanks for your answer 1) I haven't tried to add the --api-as, as it would be a pain to implement in a charsheet. Unless I'm mistaken, the sheetworkers do not have access to the playerid so it would need to be manually input and saved as an attribute in the charsheet. I have added the --current-page option though, but it didn't help 2) The answer to the MetaScript Toolbox command is no : the marker is not set 3) Here are the two logged message when I click the condition in the sheet.&nbsp; First one is the token-mod command, second one is the message sent to the chat. Both are always sent when the condition is set (and unset). "{ &nbsp; \"content\": \"!token-mod --current-page --ignore-selected --ids -ODVt1SPLLdrzQ2PfIgM --set statusmarkers|+cof2-aveugle\", &nbsp; \"playerid\": \"-O6FXipFiJIA0KsPvXcF\", &nbsp; \"selected\": [ &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; \"_id\": \"-ODW72FlTvSJvs8pgXQ7\", &nbsp; &nbsp; &nbsp; \"_type\": \"graphic\" &nbsp; &nbsp; } &nbsp; ], &nbsp; \"type\": \"api\", &nbsp; \"who\": \"StéphaneD (GM)\", &nbsp; \"variables\": { &nbsp; &nbsp; \"all\": {}, &nbsp; &nbsp; \"alltables\": {}, &nbsp; &nbsp; \"mules\": {} &nbsp; }, &nbsp; \"mules\": [], &nbsp; \"lastIndex\": 0, &nbsp; \"unlock\": { &nbsp; &nbsp; \"zeroframe\": \"-OVR5iVC8FAfybsZ_IGy\" &nbsp; }, &nbsp; \"apitrigger\": \"ZeroFrame-OVR5iVC8FAfybsZ_IGz\", &nbsp; \"origcontent\": \"!token-mod --current-page --ignore-selected --ids -ODVt1SPLLdrzQ2PfIgM --set statusmarkers|+cof2-aveugle\", &nbsp; \"parsedinline\": [], &nbsp; \"globals\": {} }" "{ &nbsp; \"content\": \"&nbsp; &nbsp;{{perso=Kamshaka}} {{color=}} {{lsub=Condition }} {{rsub=Aveuglé }} {{text=Kamshaka subit les effets suivants :&lt;br/&gt;\ -5 en Initiative&lt;br/&gt;\ -5 en Attaque Au Contact&lt;br/&gt;\ -5 en Défense&lt;br/&gt;\ -10 en Attaque A Distance&lt;br/&gt;\ Pas d'attaque magique nécessitant de voir la cible }}&nbsp; {{token=[x](<a href="https://files.d20.io/images/420248912/Abm0Zdj2mllI47yRjGDc2w/max.png" rel="nofollow">https://files.d20.io/images/420248912/Abm0Zdj2mllI47yRjGDc2w/max.png</a>) }} \", &nbsp; \"playerid\": \"-O6FXipFiJIA0KsPvXcF\", &nbsp; \"rolltemplate\": \"cof2\", &nbsp; \"target\": \"gm\", &nbsp; \"target_name\": \"GM\", &nbsp; \"type\": \"whisper\", &nbsp; \"who\": \"StéphaneD (GM)\", &nbsp; \"variables\": { &nbsp; &nbsp; \"all\": {}, &nbsp; &nbsp; \"alltables\": {}, &nbsp; &nbsp; \"mules\": {} &nbsp; }, &nbsp; \"mules\": [] }" So, it looks like the chat messages are actually sent by CRP. I can see them by putting the input focus in the chat window and pressing the up key BTW, originally I was doing all the tests in the sheet dev sandbox. I tested in a regular game as well, just in case it would be some problem in the sandbox only. But same issue. Hope this helps
1752861101
timmaugh
Forum Champion
API Scripter
OK, that should be a good start of information. Let me see if I can summon the arcane one to look at this...
1752861632
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Can you share a link to your sheet code and the line number where the relevant code starts?
1752910950
StéphaneD
Pro
Sheet Author
API Scripter
Hi Scott C. Scott C. said: Can you share a link to your sheet code and the line number where the relevant code starts? Sure I am maintaining a repo for this sheet separate from Roll20 repo @&nbsp;<a href="https://github.com/stephaned68/COF2e/tree/main" rel="nofollow">https://github.com/stephaned68/COF2e/tree/main</a> The code that handle the conditions change is @ 10845-10865 The code that specifically tries to manage the statusmarkers via TokenMod is @ 10856-10859 The tokenMod() function builds a token-mod command string The sendChatCmd() function sends a command to chat via the CRP functions startRoll() / finishRoll() functions