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

findObjs Question

Can you do a partial string match with findObjs? I want to store multiple values in the gmnotes in a comma delimited list and return that token/graphic if the first item in the list is the string "MyNPC" for example. Am I better off trying to search for and labeling my tokens with a status marker? How would I do that? Like this? findObjs({_type: "graphic", status_greenmarker: true}) Can anyone help me out with this? I'm not sure what to do to get a list of objects with a partial string match and if I can't I need to make sure I know how to properly search by status marker..
1524605079

Edited 1524605092
The Aaron
Pro
API Scripter
No, you'd need to either use filterObjs() to pass a predicate function to test the objects, or better, take the results from findObjs and filter them afterwards. let matches = filterObjs( (o) => 'graphic' === o.get('type') && true === o.get('status_greenmarker') && /MyNPC/i.test(o.get('gmnotes').split(/\s*,\s*/)[0]) ); Or better: let matches = findObjs( { type: "graphic", status_greenmarker: true}) .filter((o) => /MyNPC/i.test(o.get('gmnotes').split(/\s*,\s*/)[0])); The second is better as it can take advantage of indexing on type and possibly status_greenmarker to get results faster.
1524605810

Edited 1524605995
MyRoll20Stuffs
API Scripter
EDIT: Nevermind I think I got it.
1524606739

Edited 1524606781
MyRoll20Stuffs
API Scripter
For some reason when I output my gmnotes I get this: North%2C%203000%2C%205 It's formatting the commas as "%2C" and if there are spaces they are also formatted as a %20 Is there a function I can run on the string to fix this? Why is it doing this?
Okay so I'm using this function: decodeURIComponent And it's replacing space/commas correctly now. Now I'm running into another issue... The Aaron, do you mind if I PM you my script and you can take a look at it for me? I'll explain the trouble I'm having with it.
1524617110
The Aaron
Pro
API Scripter
I don't mind at all, send it over!
No need now. With a little reading and a lot of trial and error I got what I was having trouble with figured out. I'm going to share the script with everyone when it's done still needs some work. Which brings me to a question I have: I have a global variable in this script that I want to be able to set in-app with a ! command Can you point me to any wiki articles relating to the topic or give some examples?
1524620276
The Aaron
Pro
API Scripter
Persisted data is often stored in the state:&nbsp; <a href="https://wiki.roll20.net/API:Objects#state" rel="nofollow">https://wiki.roll20.net/API:Objects#state</a> I’d start with that. Be sure you understand the implications of the shared global object.&nbsp;