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

Where is the Default Token information stored?

1407781609

Edited 1407781666
Is it possible to manipulate a character's Default Token via the API? When duplicating a character with a Default Token, the duplicate character's Default Token will link to the original character, not the duplicate. Because I link each token's HP to its character's attributes, this makes it a bit tedious to create groups of mobs. I have to duplicate the original, drag and drop the token, relink the character name, relink the bars, then save the new Default Token. But if I could somehow manipulate the Default Token for a particular character in the API, I could theoretically make this process a lot smoother. However, it doesn't seem like the Default Token is visible in the API and it's not documented anywhere in the wiki. Is it hidden somewhere or is it simply inaccessible?
1407782270

Edited 1407782318
The Aaron
Roll20 Production Team
API Scripter
You would expect it to be in the Character Object , but It doesn't seem to be available. However, I think your specific issue can be solved by reading this wiki page . (...steals another of Phnord's nickels...)
Aaron said: You would expect it to be in the Character Object , but It doesn't seem to be available. However, I think your specific issue can be solved by reading this wiki page . (...steals another of Phnord's nickels...) Unfortunately, the wiki page you provided doesn't really resolve my problem. I want the "mooks" to have linked bars because I've implemented scripts to automatically deal damage and if I have a bunch of identical tokens, there's no way to deal damage to just one based on a click action. Let me be a little more clear. In most cases, my players deal damage by clicking a macro button corresponding with the weapon they wish to use, followed by clicking on the target (or targets) they wish to attack. Attack rolls are made and, if successful, damage is dealt. Now, if the HP bars of the token representing the target were unlinked, how would I modify that bar? I could look up the token based on its name, but if I had multiple tokens linked to the same character sheet (as would be the case with "mooks" as described in the wiki), there would be no way to differentiate between the token that the player clicked and any other token on that page with the same name. I could try to have the API guess which token to apply the damage to based on distance from the player token, but that would only work assuming only one token representing that character is threatened by the player for that attack. If I could tell where on the map the player clicked, that would probably be sufficient, but that information is not currently accessible. So the only solution I have is to create unique character sheets for each "mook" so that they are uniquely identifiable by the API. I also have other systems in place that only work if each character token is represented by a unique character sheet. Buffs, debuffs, conditions, spell casting... all of this stuff only works if each token has its own character sheet to reference. It's nothing I can't live with -- like I said, I can work around it, it's just time-consuming and a bit tedious -- but being able to directly modify a Character Object's "Default Token" would probably make this process significantly easier. I also just find it a bit odd that this data is absent from the Character Object. One would assume that it would have something like a "defaulttokenid" value that references the id of the token object that it copies when you drag-and-drop or something. It makes me wonder how this data is actually stored within the system and if it's just not made accessible through the API for some reason. In any case, thanks for your response.
1407786029
The Aaron
Roll20 Production Team
API Scripter
Are the players selecting the token to attack with @{target|token_id} ?
1407786291
The Aaron
Roll20 Production Team
API Scripter
Graphic (Token/Map/Card/Etc.) Property Default Value Notes _id A unique ID for this object. Globally unique across all objects in this campaign. Read-only. It's possible you may have not noticed that each instance of a mook you drag onto the map has a unique id associated with it. Two cultist mooks will have different ids. @{target|token_id} will give you the token id of the specific mook your player clicked on, which you can then use with the API to grab precisely that one token and adjust it's bars.
1407786376
The Aaron
Roll20 Production Team
API Scripter
Probably the internally, the Character has a copy of the relevant details of the token, and is using it as a prototype (in the pattern sense, not the extension sense) to create the tokens dragged onto the map.
I didn't know that you can call the token id as an attribute! That's actually really useful and could make other things much easier down the line, I think. Thanks a lot for making me aware of that. However, it still doesn't help situations where, for example, a character casts something like Spell Resistance on a mook, giving just that individual mook SR 19 or something. Since an individual token can't store its own individual attributes, it needs to be tied to a character object that can. I could theoretically keep track of status conditions using a token's status icons or GM notes, but that would mean I'd have to factor that into scripts used for calculating various roll results rather than just adjusting a value on a character sheet.
1407797851

Edited 1407797867
The Aaron
Roll20 Production Team
API Scripter
So, you want to store the status somewhere and pull it out in scripts? Use the state object. Be sure to namespace your use of the state object. I create an entry with the name of my script, something like this: var AScriptName = AScriptName || (function() { 'use strict'; var version = 0.3, schemaVersion = 0.1, HandleInput = function(msg) { /* api commands */ ///////////////////////////// // after some processing ///////////////////////////// if(!_.has(state.AScriptName.mookStatus,token_id)) { state.AScriptName.mookStatus[token_id] = { SR: 19, SomethingElse: 'data' }; } else { state.AScriptName.mookStatus[token_id].SR=19; } }, checkInstall = function() { if( ! _.has(state,'AScriptName') || state.AScriptName.version !== AScriptName.schemaVersion) { /* Default Settings stored in the state. */ state.AScriptName = { version: AScriptName.schemaVersion, mookStatus: {} }; } }, registerEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: registerEventHandlers, CheckInstall: checkInstall }; }()); on("ready",function(){ 'use strict'; AScriptName.CheckInstall(); AScriptName.RegisterEventHandlers(); });
Aaron said: So, you want to store the status somewhere and pull it out in scripts? Use the state object. Be sure to namespace your use of the state object. I create an entry with the name of my script, something like this: var AScriptName = AScriptName || (function() { 'use strict'; var version = 0.3, schemaVersion = 0.1, HandleInput = function(msg) { /* api commands */ ///////////////////////////// // after some processing ///////////////////////////// if(!_.has(state.AScriptName.mookStatus,token_id)) { state.AScriptName.mookStatus[token_id] = { SR: 19, SomethingElse: 'data' }; } else { state.AScriptName.mookStatus[token_id].SR=19; } }, checkInstall = function() { if( ! _.has(state,'AScriptName') || state.AScriptName.version !== AScriptName.schemaVersion) { /* Default Settings stored in the state. */ state.AScriptName = { version: AScriptName.schemaVersion, mookStatus: {} }; } }, registerEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: registerEventHandlers, CheckInstall: checkInstall }; }()); on("ready",function(){ 'use strict'; AScriptName.CheckInstall(); AScriptName.RegisterEventHandlers(); }); That could work, but I prefer to work out of the character sheet so that the information is easily accessible. State variables are difficult to check, so it would be difficult to verify whether or not a particular mook has Spell Resistance or a boost to its AC or something like that. For example, if SR was stored as a state variable, if I wanted to remember whether or not a particular mook has SR, I would have to use some kind of API command to get that information. However, if it's just in the character sheet, I can just bring that up and look for myself. Also, wouldn't state variable information be inaccessible from Roll20 macros? Like say I wanted to roll against a character's SR and it was kept as a state variable, wouldn't that be impossible to do from a macro or a chat command?
1407858624
The Aaron
Roll20 Production Team
API Scripter
You would have to create a command that does the check for you and pass it relevant data. Alternatively, you could setup attributes on the character, and write commands in the API that set them and clear them based on the selected token: /w gm Copy stats for the selected token out of state and onto the represented character !morph-to-mook ${selected|token_id} /em does attack that references any mook specific state on the character /w gm Clear stats for the selected token out of the character it represents !demorph ${selected|token_id} Not a perfect solution, but if you're writing all the macros, it could be done. You could write those as non-character macros and let players call them: #{pre-attack-setup} /em player macro stuff #{post-attack-teardown}
1407861287

Edited 1407861460
Aaron said: You would have to create a command that does the check for you and pass it relevant data. Alternatively, you could setup attributes on the character, and write commands in the API that set them and clear them based on the selected token: /w gm Copy stats for the selected token out of state and onto the represented character !morph-to-mook ${selected|token_id} /em does attack that references any mook specific state on the character /w gm Clear stats for the selected token out of the character it represents !demorph ${selected|token_id} Not a perfect solution, but if you're writing all the macros, it could be done. You could write those as non-character macros and let players call them: #{pre-attack-setup} /em player macro stuff #{post-attack-teardown} That's an intriguing idea. When a token is selected, the changes to the character sheet can be applied and then removed after the action is completed. It still means I can't check buffs and debuffs by referring to a character sheet, but it at least sounds functional. Still, the ability to modify the Default Token data would be handy and make it easier for each token to have its own character sheet.
1407861733
The Aaron
Roll20 Production Team
API Scripter
If you want each token to have it's own character sheet, you can do that. You'll rapidly have an unmanageable number of characters, but here's how you can do it: Subscribe to the on('create:graphic',...) event. Add a sentinel value to characters you want to copy, say Mook =1 Assume there will be a sentinel value for copied mooks, say MookCopy =1 If the graphic has a character that it represents, and has Mook set to 1 but does not have MookCopy Create a new character Copy all the attributes, settings, abilities to it change the represents on the created graphic to point to the new character (Warning, there is a bug in creating objects, Be sure to look at this thread: <a href="https://app.roll20.net/forum/post/733277/api-fireb" rel="nofollow">https://app.roll20.net/forum/post/733277/api-fireb</a>... )
1407861910
The Aaron
Roll20 Production Team
API Scripter
Alternatively, you could use the !morph-to-mook and !demorph command in separate buttons to set the state of the character so you can look at it, then set it back after.
Aaron said: If you want each token to have it's own character sheet, you can do that. You'll rapidly have an unmanageable number of characters, but here's how you can do it: Subscribe to the on('create:graphic',...) event. Add a sentinel value to characters you want to copy, say Mook =1 Assume there will be a sentinel value for copied mooks, say MookCopy =1 If the graphic has a character that it represents, and has Mook set to 1 but does not have MookCopy Create a new character Copy all the attributes, settings, abilities to it change the represents on the created graphic to point to the new character (Warning, there is a bug in creating objects, Be sure to look at this thread: <a href="https://app.roll20.net/forum/post/733277/api-fireb" rel="nofollow">https://app.roll20.net/forum/post/733277/api-fireb</a>... ) Is there an easy way to copy over all the attributes when creating a new character based on an existing one?
1407868451
The Aaron
Roll20 Production Team
API Scripter
There is some syntactic sugar you can use. Check out this script: <a href="https://app.roll20.net/forum/post/1067109/script-c" rel="nofollow">https://app.roll20.net/forum/post/1067109/script-c</a>... In it, I copy en masse a bunch of abilities. The same process can be modified to copying over attributes. Note that I'm using the underscore.js library heavily, so you might need to become familiar with it for this code to make sense. It's extremely functional, but very terse at times. I'm happy to explain any of it in excruciating detail, if that's helpful.
Aaron said: There is some syntactic sugar you can use. Check out this script: <a href="https://app.roll20.net/forum/post/1067109/script-c" rel="nofollow">https://app.roll20.net/forum/post/1067109/script-c</a>... In it, I copy en masse a bunch of abilities. The same process can be modified to copying over attributes. Note that I'm using the underscore.js library heavily, so you might need to become familiar with it for this code to make sense. It's extremely functional, but very terse at times. I'm happy to explain any of it in excruciating detail, if that's helpful. I believe I asked for an *easy* way :P I've actually already implemented some scripts for manipulating attributes, so I could theoretically write a complicated script for copying over individual attributes for a new character, I just would rather not have to, lol. It would be nice if we could call the "Duplicate Character" function used by the Roll20 system from the API, then this would be a trivial matter. Still, thanks for the great input. I've already implemented some of your suggestions and it's made certain things much simpler.
1407869576
The Aaron
Roll20 Production Team
API Scripter
No worries. =D