I want to use the rest function to access online data. This work, but if the data is large, whats the solution to "store it". Especially if I do a small addon for the user in my group. Id like to have like a "check local stuff" and a "refresh local stuff" so I dont need to poll the server all the time, but im not too sure how im supposed to store data that should ideally be available to all players
#Storing external data
1 messages · Page 1 of 1 (latest)
How big is your "large"?
I store 5e JSON data for books into a token property.
Accessibility in a macro is speedy (e.g. bigJSON = getProperty(thisProp) but if you open the token to view the JSON data in Token Properties, I've had it take minutes to show the same data
If you are doing an add on it is better to use the data functions, as they will reduce the amount of time parsing/reparsing/converting to string of any JSON, which could be significant time wise if stored in a toke property
Book ya. So If someone use the addon, I need to create some kind of libtoken and dump the stuff in a property?
wdym data function
Listen to Craig 🙂
https://wiki.rptools.info/index.php/data.getData
Also keep in mind that there are strategies for minimizing the performance cost. For example, one token could have 26 properties, where all of the data starting with “A” is in one property, and so on. You’ve just split the size of the data set into 26 chunks, and while they’re not all going to be the same size, they will definitely be smaller than all of them together!
At some point, the JSON stored in token properties will be stored natively and retrieval will be faster. Right now, all token properties are stored as strings and must be converted back and forth when loaded/saved on the token. (Edit: Apparently this is no longer part of the long term plan. See next post.)
Just ignore the above, use the data functions and you wont run into these problems, at the moment JSON storage on properties as a non string is a "don't touch as it will break too many things" so it may never change
it seems cool, but I cant find the documentation on the wiki for https://wiki.rptools.info/index.php/data.setData. Maybe its obvious and im just a dummy, but I dont really got an idea on how to use it.
Like there seem to be a namespace specifier? Is it like a globla thing, anyone from any token can call setdata and store it "somewhere"?
Does it persist when the campaign is saved or is it temp?
If I syntaxually compare, I'd assume (maybe wrongly) that the dataset on a set would be the same as the get
And I don't know the answers to your other questions 🙁
Yeah its same as getData just with an added parameter which contains the data to set. Be aware unlike token properties these values have a type so if you set it as a number then later try to set it to json it will fail, you can use data.removeData first if you want to change its type
The namespace is global, you can (and probably want to so you dont have too much to remember) use your addon namespace here too.
It persists with the campaign and is sent to all clients
the get data example is: [r: data.getData("addon:", "ca.pf2e", "events")]
"addon:" is a type? What are available type
The namespace is really there so if two people write something that has an "inventory" data field name, they are not clobbering each other if both are used in same campaign
Type can be anything you want, but you have to create types and namespaces with
data.createNamespace(type, namespace)
That means you can have the same namespace in different types...
There is a 'addon:' '<addon namespace>' created automatically for you for each addon
so I need to create a "json" type for my personal "namespace", and then I can put a json with Key "my key", type "json", "namespace". Which will be a campaign stored data
no type is just an overaching type of store, its not the datatype, if you had an addon already with the namespace net.myaddon you could just do
[h: data.setData('addon:', 'net.myaddon', key, jsonValue)]
The type in this case indicates the data belongs to the addon
oh... I must admit its not intuituve to me, thank you!
if you have an add on, generally unless you are doing something really special you will just want to use type = addon: and namespace = <add on namespace>, if you have no add on then you have to create your own type and namespace to use the functions
Imma have to try that this evening. Thank you
The other advantage of using addon: add-on.namespace is it will remove the data if your addon is removed (it will not remove it if you just update your addon only if you remove it)