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

[help] 4E character importer - overwrite not create

Hi Community Since HoneyBadger isn't going to update his Awesome Character Importer for the Character Sheet, (ref: <a href="https://app.roll20.net/forum/post/1113190/slug%7D#" rel="nofollow">https://app.roll20.net/forum/post/1113190/slug%7D#</a>... ) Sorry in advance for messing up your code HoneyBadger! I'm absolutely horrid at this JavaScript (still learning) :D. I'm working on a fix that'll work for my group, but I've run into an issue with the script, - or rather with my own change. So far I've managed to change some of the fields (Abilities) it gets, sort some of the RegEx to get the data, and update a character sheet already created with the Power Cards (which is essentially what we want) But I've run into a problem Which is trying to update these two to do overwrite instead of create. - AddPCAttribute (attr, value, charid) - AddPCPower (powername, powerstring, charid, tokenaction) These two functions creates a new Attrribute or Ability Regardless if the Character already has them, but that eventually leads to some intense macro mayhem after 2 updates as they get repeated each time. I've tried to add some kind of check to see if the Ability is already there, but with no positive result. And I'm a little curious on how to do "update" an object. What I tried was something along these lines, but I'm aware that this isn't how it's done (as it didn't work :) function AddPCPower (powername, powerstring, charid, tokenaction) { var pwToAdd = findObjs("ability", { name: powername }); if (pwToAdd.length &gt; 0) { pwToAdd.set("ability", { action: powerstring, istokenaction: tokenaction, characterid: charid } else { createObj("ability", { name: powername, description: "", action: powerstring, istokenaction: tokenaction, characterid: charid } }); I'm completly bombed on what to do, but perhaps someone could help me look in the right direction? Best Regards //L
1433866933

Edited 1433867477
The Aaron
Pro
API Scripter
The issue is that f indObjs() only takes a single object parameter. You have: var pwToAdd = findObjs("ability", { name: powername }); What you want is (note that I added the character id, so you only get the one with that name for that character): var pwToAdd = findObjs({ type: 'ability', characterid: charid, name: powername }); It's confusing because getObj() and createObj() both take a string parameter first which designates the type of object, whereas findObjs() searches across all object types. I can't count the number of times I've hit this same problem. =D Additionally, your .set() needs to be changed. findObjs() will return an array, so pwToAdd will be that array, and thus pwToAdd[0] will be the first object in the array that matched. .set() is a little confusing because you can call it in two ways: .set( &lt;key&gt;, &lt;value&gt; ), or .set( &lt;object&gt; ). For what you're doing, the &lt;object&gt; version is more approprite: pwToAdd [0] .set({ action: powerstring, istokenaction: tokenaction }); There are also a few missing }); in your code. Fully rewritten, it should look something like this: function AddPCPower (powername, powerstring, charid, tokenaction) { var pwToAdd = findObjs({ type: 'ability', characterid: charid, name: powername }); if (pwToAdd.length &gt; 0) { pwToAdd[0].set({ action: powerstring, istokenaction: tokenaction }); } else { createObj("ability", { name: powername, description: "", action: powerstring, istokenaction: tokenaction, characterid: charid }); } });
1433920855

Edited 1433923534
Once again thanks Aaron, I see what you did there, it helped immensely. :) //L
Btw. Aaron, have you experimented with your "Use Power" API and making "power cards" API as well as the 4E Character sheet? I'm trying to figure out if I can get them to work so. When I create the Power Cards, it will at the same time create the "Use Power" triggers. Best Regards //L
1433936528
The Aaron
Pro
API Scripter
I haven't I'm afraid. You certainly should be able to inject the calls in the same way you add the !power calls.
I got it to work (somewhat) at least it'll work for my group of players, thanks anyway Aaron. :) //L
1433941241
The Aaron
Pro
API Scripter
no problem!