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

Change Event On Character Bio Property

1601547704

Edited 1601547785
Hi folks, I'm trying to, if possible, have any editing of the many characters' bio entry in the journal unwittingly (or deliberately! LOL) by players be reversed by the on change event.&nbsp; I'm able to do it for the character name: on("change:character:name", function(obj, prev) { // check if the changed object has a record let newname = obj.get("name"); let oldname = prev["name"]; if (newname !== oldname) { //sendChat ("", newname + "&lt;br&gt;" + oldname) obj.set("name", oldname); } }); Of course, the above can't be done for bio; when I used "bio" instead of "name", I got the following error: "Error: You must pass a callback function to .get() when getting the bio, notes, defaulttoken, or gmnotes of a Character or Handout." Which was expected, of course, led me to the help at: <a href="https://roll20.zendesk.com/hc/en-us/articles/360037772793#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360037772793#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous</a> My biggest experience with callback functions is function(msg) on sendChat, which I use an awful lot.&nbsp; Is there anyway I can use the obj and prev arguments of the change events? Thanks in advance for any guidance here.&nbsp; -- Tim
1601556865
The Aaron
Roll20 Production Team
API Scripter
You just need to use a callback on the get and it becomes pretty simple: on("change:character:bio", function(obj, prev) { // check if the changed object has a record obj.get("bio",(newbio) =&gt; { let oldbio = prev["bio"]; if (newbio !== oldbio) { //sendChat ("", newbio + "&lt;br&gt;" + oldbio) obj.set("bio", oldbio); } }); }); The comparison between newbio and oldbio is probably redundant.&nbsp; The event shouldn't fire unless something was changed, but it doesn't hurt to leave it in there.
The Aaron said: You just need to use a callback on the get and it becomes pretty simple: Thank you, once again. -- Tim
1601560063
The Aaron
Roll20 Production Team
API Scripter
No problem!
1601639076

Edited 1601639214
The Aaron said: No problem! Oops, Aaron, I just realized that the result of: let oldbio = prev["bio"]; appears to be a number.&nbsp; Any ideas? To illustrate, I've commented off some parts of my code to just produce the new then old bios: // Character bio. The bio property is a bit different, // <a href="https://app.roll20.net/forum/post/9237545/change-event-on-character-bio-property/?pageforid=9237731#post-9237731" rel="nofollow">https://app.roll20.net/forum/post/9237545/change-event-on-character-bio-property/?pageforid=9237731#post-9237731</a> on("change:character:bio", function(obj, prev) { // check if the changed object has a record obj.get("bio",(newbio) =&gt; { let oldbio = prev["bio"]; if (newbio !== oldbio) { sendChat ("", newbio + "&lt;br&gt;&lt;br&gt;*" + oldbio + "*", null, {noarchive:true}); /* let personlabel = getinsult(); sendChat ("", 'Tim said not to mess with the bio &amp; info tab, but ' + 'you tried to **change the "biography", you ' + personlabel + '**', null, {noarchive:true}); obj.set("bio", oldbio); */ } }); }); But this screen shot shows newbio + "&lt;br&gt;&lt;br&gt;*" + oldbio + "*" and the number for oldbio.&nbsp; This is one of my less wordy character bios: This also happens with player accounts, of course. Sorry for being a bother. -- Tim