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

Imports/Exports Roll 20 Characters as JSON objects

March 24 (10 years ago)
Imports/Exports Roll 20 Characters as JSON objects. You can export all your characters and share them with other Roll 20 Users.

https://github.com/mikrasov/Roll20-Scripts/blob/ma...
March 25 (10 years ago)
Gen Kitty
Forum Champion
This is... interesting. What sort of output do you get for the export?
March 25 (10 years ago)
It is a JSON object that contains all the attributes and abilities of the character you are exporting.
So if you are using the same character sheet as another DM all the stats and attacks carry over.

Theoretically it can do bios and notes, but it is by default disabled in the script as it is likley to generate files that are too large for the API to handle.
March 25 (10 years ago)
The Aaron
Pro
API Scripter
I see you're processing 1 full character every .5 seconds. I assume you're hitting the API Heartbeat issue? You could likely further subdivide your character processing and get below the threshold that causes an error. For example, you could export everything as a list of object to import, so each attribute or ability would fall in it's own timed cycle.

Something else you might find useful is the Base64 encode/decode library I ported to the Roll20 API. It would let you dump out a block of text that can be copied and pasted as an argument to the API, or pasted into a handout, rather than editing the script for each import.
March 25 (10 years ago)
Yeah I had to slow down processing so that the API could keep up. I tried a handout based approach initially, but that required escaping html content. I decided to go with plain old JSON objects for ease of sharing. The Base64 encode is way cool. If people use this script I might make it an option to import/export as encoded text from a handout.
March 25 (10 years ago)
The Aaron
Pro
API Scripter
Let me know if you have any issues! =D
March 25 (10 years ago)
Gen Kitty
Forum Champion
I don't know JSON from Bob or Adam.

I'm looking for something where I could export a character, edit the abilities/attribute data with something like notepad++, and then reimport the character back into the game. Would your script allow for this? (Answers in plain english for the non-programmer would be vastly appreciated)
March 25 (10 years ago)

Edited March 25 (10 years ago)
The Aaron
Pro
API Scripter
If you can understand how to change the name of the sun image in this structure, you should be fine to make changes to the output of this script:
{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}    
It might come out like this:
{"widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500 }, "image": { "src": "Images/Sun.png", "name": "sun1", "hOffset": 250, "vOffset": 250, "alignment": "center" }, "text": { "data": "Click Here", "size": 36, "style": "bold", "name": "text1", "hOffset": 250, "vOffset": 100, "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" } }}
There are some ways you can make it look nicer if that's the case.
March 25 (10 years ago)
Gen Kitty
Forum Champion
Hm. I'd change the title & name in the window section, and name in the image section. I'd test after every change to make sure what was happening was what I was expecting :>
March 26 (10 years ago)

GenKitty said:

I don't know JSON from Bob or Adam.

I'm looking for something where I could export a character, edit the abilities/attribute data with something like notepad++, and then reimport the character back into the game. Would your script allow for this? (Answers in plain english for the non-programmer would be vastly appreciated)

Yes.
March 26 (10 years ago)
It might be helpful to use a https://www.jsoneditoronline.org/ to edit the json. What would be awesome is to have a website to share characters/monsters. Got about 80 DnD 5e monsters built. Would like to be able to share trade those with other DMs.
April 21 (10 years ago)
Gen Kitty
Forum Champion
So I'm poking at this script and right now it is just sitting and spinning. I get the restarting sandbox line, and then NOTHING. How long should I wait before I worry? Is it going to try to do EVERY SINGLE CHARACTER JOURNAL in my campaign? (which really isn't what I want :/ ) Is it trying to export my archived journals?
April 22 (10 years ago)
The Aaron
Pro
API Scripter
Yes. All of that. Every character in the entire campaign, archived or no. =/
April 22 (10 years ago)
Gen Kitty
Forum Champion
Grf.

How hard would it be to adapt the script such that it is run by a character and only exports/imports THAT character journal?
Be cool if it was like a transmog setup where you select what you want. Or has a status bar or something.
April 22 (10 years ago)

Edited April 22 (10 years ago)

GenKitty said:

Grf.

How hard would it be to adapt the script such that it is run by a character and only exports/imports THAT character journal?

There'd be a bit of restructuring to do, but not too much work, especially if you didn't want it to be user-friendly. In fact, in the easiest but least user-friendly case, there's no restructuring at all: you could just make the findObjs call more restrictive in exportAll (line 50):
var characters = findObjs({_type: "character", name: "Sir Bearington"})
It would work the same way, it'd just think that "all characters" means "all characters named 'Sir Bearington'".
April 22 (10 years ago)
The Aaron
Pro
API Scripter
It's a hard problem for a few reasons:
  • how do you pick which one?
  • There aren't really good methods of getting and returning that amount of data.
It's actually easier if all you want to do is move characters between campaigns, because you can use something like base64 encoding for the transfer.
Well I'm not javascript programmer thats for sure, but what about folder access via the API?

Maybe if you create an "export" folder right off the campaign root and move what you wanted into there for a quick and painless export solution?

You could also paste what you wanted to import into an "Import folder"

Other option maybe a dual script? One that pulls all the names, and you put that into another script that asks based on the names what you want to export.. something like the GenKitty help system? "Export Character "Bob" Yes/No "Fred" Yes/No

Just a few thoughts, about ready to hit the sheets myself.
April 22 (10 years ago)
Gen Kitty
Forum Champion
How do you pick? The script exports the character attached to the token that ran the macro 'export me'. I just can't imagine how the import side would work.

This inability to import/export characters drives me a little nuts at times. Making changes to a number of abilities at the same time is a frustrating and annoying process, as I've complained before. It's the only time I miss Gametable. :/
April 22 (10 years ago)
The Aaron
Pro
API Scripter
I think I can make you a solution... but I've already failed to go to bed at a reasonable time for the 3rd night in a row. Let's see what tomorrow brings.
April 22 (10 years ago)
vÍnce
Pro
Sheet Author

The Aaron said:

I think I can make you a solution... but I've already failed to go to bed at a reasonable time for the 3rd night in a row. Let's see what tomorrow brings.

The 4th night in a row...
April 22 (10 years ago)
Gen Kitty
Forum Champion
*patpat* Do GroupInit first ^_-
April 22 (10 years ago)
GenKitty, would a possible workaround be setting up a campaign with just the characters you wish to import/export then transmogrify them back to where they need to be? Basically setup an import/export sandbox.
April 22 (10 years ago)
Gen Kitty
Forum Champion
Possible? Sure. Many things are possible. It is, however, an extremely less than satisfactory work around. I'll give it a try this weekend, using this script. That will give me a chance to figure out how to accurately copy the PCs from Actual to Sandbox. I'll copy the whole campaign over to Test, first, because I see this all going horribly horribly wrong somewhere along the line.

Isn't there some way to use character IDs such that a single journal could be imported?
April 22 (10 years ago)
The import side of it is easy: the script imports whatever JSON you give it, so you can just only copy the parts that you want (or only generate the parts you want, using the trick mentioned above or some other modification to the script). I haven't actually run the script, but it looks like it should generate output that looks like the following (modulo some whitespace that I'm adding for clarity):
{
  version: <something>,
  characters: [
    {
      name: <first character name>,
      abilities: [...],
      attributes: [...]
    },
    {
      name: <second character name>,
      abilities: [...],
      attributes: [...]
    },
    ...
  ]
}
You can delete out the chars you don't want from the "characters" array (this will be easiest if you either add indentation like above or use a text editor that does brace-matching so you can figure out which closing brace matches up with which opening brace and only delete what you want to).
April 25 (10 years ago)
Gen Kitty
Forum Champion
It's now the weekend and I'm able to test this out. Family distracted and headphones on!

I created a test copy of the campaign, and then an import/export campaign just for using this script. The transmogrifier is surprisingly easy to use.

However, I've run into a minor annoyance.

In the journal, the ability is formatted:


!power {{
--name|**@{selected|token_name} | Melee Basic Attack**
--leftsub|At-Will
--rightsub|Standard Action
--Keywords:|Weapon
--Attack:|[[1d20 + @{HalfLevel} + @{Str} +@{Blade-P} + @{Blade-A-CFEM} + ?{MiscToHit?|0} ]] vs [[@{target|Foe|AC}]] @{target|Foe|token_name}'s AC
--Hit:|[[ ([NH]1d8) +@{Str} + @{Blade-D-FEMM} + ?{MiscToDamage|0} ]] damage | Crit [[ (1*8) +@{Str} + @{Blade-D-FEMM} + [NH]2d6 + ?{MiscToDamage} ]]
}}


However, when it is exported as JSON, I get this:


"!power {{\n --name|**@{selected|token_name} | Melee Basic Attack**\n --leftsub|At-Will\n --rightsub|Standard Action\n --Keywords:|Weapon\n --Attack:|[[1d20 + @{HalfLevel} + @{Str} +@{Blade-P} + @{Blade-A-CFEM} + ?{MiscToHit?|0} ]] vs [[@{target|Foe|AC}]] @{target|Foe|token_name}'s AC\n --Hit|[[ ([NH]1d8) +@{Str} + @{Blade-D-FEMM} + ?{MiscToDamage|0} ]] damage | Crit [[ (1*8) +@{Str} + @{Blade-D-FEMM} + [NH]2d6 + ?{MiscToDamage} ]]\n}}"


Now, I spent a good year or maybe more doing my powercards in single line macros and I can deal with this... but it would be really really nice if the multi-line format could be preserved in the export. Is this possible? I'm betting not, but a girl can hope! (I suspect it would require a change to the JSTools plugin for Notepad++, which is outside the scope of anyone here. I think.)

Now, for importing....

When I try to import the resulting string, I keep getting

Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info...
For reference, the error message generated was: Unexpected token {

I fixed this by removing the {} on Line 32 and replacing them with my string. I suggest the comment for that line mention you replace the {} rather than trying to put your string between them :>

After the import, I did get this warning message: "ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info."

When i go into the campaign, I see that I now have TWO Ekima journals, one with an avatar and default token, and one without.

As a test, I removed BOTH journals and re-imported. I'm left with a journal that is not an exact backup of the original. It didn't retain the controlling player, the tags, the avatar, nor the default token. Player is no big deal, but the rest are a dealbreaker for my purposes :/

For my purposes, a script has to over-write an existing journal's Attributes & Abilities tab, and is probably only likely to be able to do so if it can reference the unique ID string -- likely by being triggered by a macro from the specific journal. Likely something such as '!ImpExp --IMPORT'

Michael N., should I start a new request thread, or are you willing to tackle this as a new version of your existing script?
April 25 (10 years ago)
Unfortunately, a lot of that isn't possible in the current state of the API. The error message you got is due to the fact that tokens and avatars can only use images from a Roll20 library, not from the web. Default token is read-only, and the API has no access to tags (I'm pretty sure there's a suggestion at least for the latter in the suggestions forum). If you're just wanting to manage a characters abilities (I assume this is in pursuit of improving the character macro management system you mentioned in some other thread), something more purpose-built may be better for you.
I've been tossing around the idea of making a handouts-based filesystem-analogue, which would help with something like this (making it easier for a script to dump to and load from a handout, so it can all be done from within the game). Maybe I'll put in some work on that this weekend and use this as a test case for it.
April 25 (10 years ago)

Edited April 25 (10 years ago)
Gen Kitty
Forum Champion
The Aaron's doing something similar.

This script works great for moving character journals between campaigns, and doesn't need any tweaks for that use-case. I don't want anyone thinking it's a failed script. I just need a screwdriver instead of a hammer. or something like that :>

And yeah, this is for mass editing & re-importing of character macros.

I've got all five PCs macros up in files now, going through and updating everyone's macros to the latest & greatest update in powercards -- some of these macros haven't been touched since v1.x. And I'm dreading the slow, laborous, ability by ability copy-select-delete-paste-save process. Which is why they haven't been updated in so long....