#the content field of the chat message
1 messages ยท Page 1 of 1 (latest)
It's for PBTA
"<section class="pbta-chat-card">
<div class="cell cell--chat">
<div class="chat-title row flexrow">
<h2 class="cell__title">Strength</h2>
</div>
<div class="row"><em>Strength (+1)</em></div>
<div class="row result partial">
<div class="result-label">Partial success</div>
</div>
<div class="roll partial"><div class="dice-roll">
<div class="dice-result">
<div class="dice-formula">2d6 + 1 + 0</div>
<div class="dice-tooltip">
<section class="tooltip-part">
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">2d6</span>
<span class="part-total">8</span>
</header>
<ol class="dice-rolls">
<li class="roll die d6">5</li>
<li class="roll die d6">3</li>
</ol>
</div>
</section>
</div>
<h4 class="dice-total">9</h4>
</div>
</div>
</div>
</div>
</section>"```
That's the content of the "content" field in the data
Damn - this is in preCreate too
you need to find a place before this html is generated OR come in after the chat message has been created, extract any roll data it has in its flags, create a new roll from that data, modify the roll, evaluate the roll, and store it back in the chatmessage's flags
With CONFIG.debug.hooks I don't see any other hooks being called when I roll the "item" unfortunately
I don't see any roll data in the flags of either preCreate or CreateChatMessage - the only roll data is in that HTML
indeed, so you might have to parse the HTML directly after the chat message is rendered
which requires a world script to keep it in sync for all clients
Yeah I have that part as a world script already and can do it on render of the chat card - but how would I update that card?
let searchString = `<div class="dice-formula">2d6 + 1 + 0</div>`;
let replaceString = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;```
IE: here was what I was thinking - I just don't know how to "apply" this so that the chat card is updated
you update the chat message's "content" field with the new HTML string
So if I do this ```content = content.replace(searchString, replaceString);
How would I apply that to the chat card?
I tried this but no luck
let chatMessage = game.messages.get(data._id);
chatMessage.updateSource({ content: content });```
I can see my content has the right content, but the chat card isn't updating in chat
a normal update
updateSource just modifies the local data and does not trigger update hooks
Ok this works now ๐
BUT: It seems to be stuck in an infinite loop of just updating it constantly
what hook are you using?
renderChatMessage
let actorId = data.speaker.actor;
let actor = game.actors.get(actorId);
let content = data.content;
let rolltype;
if (content.includes("Strength")) rolltype='str';
if (content.includes("Agility")) rolltype="agi";
if (content.includes("Influence")) rolltype="inf";
if (content.includes("Wits")) rolltype="wit";
if (content.includes("Arcane")) rolltype="arc";
if (content.includes("Luck")) rolltype="luk";
let actorStat = actor.system.stats[rolltype];
let mastery = actor.system.attrTop.hold.value;
let searchString = `<div class="dice-formula">2d6 + 1 + 0</div>`;
let replaceString = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;
content = content.replace(searchString, replaceString);
let searchString2 = `</em></div>`;
let replaceString2 = ` Mastery (+${mastery})</em></div>`;
content = content.replace(searchString2, replaceString2);
rolltotal = content.substr(content.indexOf('"dice-total">')+1, 1);
let searchString3 = `<h4 class="dice-total">4</h4>`;
let replaceString3 = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;
let chatMessage = game.messages.get(data._id);
chatMessage.update({ content: content });
//if (actorStat.toggle)
//{
//}
});```
you may need to add some info to the optional argument of update so your hook can look at it and say "wait, this is my update, dont do anything"
Hmm - do you have an example of this?
I was hoping isroll would be enabled for the original roll but its not
here (https://github.com/trioderegion/squadron/blob/bffe26e9050980c6d2aff2af49fe99633a77f970/scripts/modules/logistics.js#L250) is where I issue an update and add an options flag (squadron.lookout.leadersflag) to the update.
and here (https://github.com/trioderegion/squadron/blob/bffe26e9050980c6d2aff2af49fe99633a77f970/scripts/modules/lookout.js#L153) is where my hook looks for that flag and stops processing
Is adding the flags to the chat message the same?
I did this chatMessage.update({ content: content, ishookupdated: true }); but ishookupdated doesn't exist when I go look for it
not flagging the chatmessage, adding information to the update process so we know its "us" doing it
Yeah that's what I tried to do with the ishookupdated - is that not the right way?
no, because that would cause another render hook and that is causing the infinite loop
I'm confused haha
At the top of my hook I was going to check if the chat message had ishookupdated and if it did then not to run the code
Should it be outside the 'content' part?
chatMessage.update({ content: content}, ishookflag: true);```
yes, but as an object (your snippet is invalid syntax)
message.update({},{ishookflag: true});
Is that correct?
nods, yea
I don't see the ishookflag when I do a get message - am I missing something?
it will be present in the preUpdateChatMessage and updateChatMessage hooks
Oh - how would I link the two hooks? If I check it in preUpdateChatMessage and it exists then I want to run the code under the renderchatmessage hook but otherwise I wouldn't
create the renderChatMessage hook as a Hooks.once when your preUpdateChatMessage hook detects (or doesnt detect) your options flag
In this case preUpdateChatMessage hook wouldn't fire until I do the update - so do I need to do a hook once first in the world script, and then do the hook.once within the PreUpdate for any subsequent ones?
im not 100% sure without digging into the code flow myself, but you definitely have the right idea
either a hook needs to fire, or needs to not fire, based on data received during preUpdate
Thanks - trying to figure out the initial trigger - Im trying to add a flag to the messages flags field but its not working
One for the initial run, and the second flag for the preUpdate
chatMessage.update({ content: content, flags: {ishookflag: true}},{ishookflag: true});
content appears to update, but flags doesn't show the flag I'm trying to add
my use of "options flag" may have been misleading
i dont think you need to actually set a flag on the chatmessage document
just that second options object with "ishookflag" should propogate throughout all chat message updating hooks
It does but I don't know how to trigger the original update (since the update hooks won't be triggered)
IE: How do I trigger my function to update the chat message when the update chat message hook won't be called yet
If I put it under RenderChatMessage I can't grab that option so I don't know if it's been done
you will be using preCreate to detect if you need to operate on this chat message, i think
preCreateChatMessage? It will have that option?
that's where you would likely set the option -- you add any info to the creation options that your later hooks need to make their decisions. Something that says "Hey, this is a roll message that needs or may need to be modified".
then, when the later hooks "take action" and update the chat message, they will add an option to the update that says "hey, this message has been handled, dont take any further action" to any of your hooks
Ok that makes sense - how do I add that option in preCreateChatMessage?
chatMessage.update({},{ishookflag: true}); }
says .update isn't valid
in the hook, you receive several arguments, the...second, or third (i forget) is the current options argument
simply say options.ishookflag = true
once you know its a message you want to handle
Oh ok!
This is what I ended up with
updateChatMessage(data, options, flags);
});
}```
Result (Mastery part is added)
Thanks very much for your help - I couldn't have figured it out without it