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

.match function not found

The Aaron in a post created exactly what I need: <a href="https://app.roll20.net/forum/post/6659598/simulate-a-for-each-loop-to-create-a-roll-query-of-all-the-items-in-a-repeating-row" rel="nofollow">https://app.roll20.net/forum/post/6659598/simulate-a-for-each-loop-to-create-a-roll-query-of-all-the-items-in-a-repeating-row</a> I tried to use this great idea but I always receive an error on the .match function (&nbsp;.match is not a function). I tried several solutions, but no way, match exists for String variables I created, but not in the one I need to use. Any suggestion? Thank you in advance
Just for making the debug easier, without searching around, a function is created for getting an array of weapons: const getRepeating Rows ForCharacter = (charID, repeatingName) =&gt; { const matcher = new RegExp(`^repeating_${repeatingName}_(-[^_]+)_`,'i'); return findObjs({ type: 'attribute', characterid: charID }).filter((a)=&gt;matcher.test(a.get('name'))) .reduce((m,a)=&gt;{ let match = matcher.match(a.get('name')); m[match[1]]=m[match[1]]||[]; m[match[1]].push(a); return m; },{}); }; And it is called by a function (mine will be different, but better to start having a working function): on('chat:message', (msg) =&gt; { &nbsp; &nbsp; //log(msg); &nbsp; &nbsp; if('api' === msg.type){ &nbsp; &nbsp; &nbsp; &nbsp; let args = msg.content.split(/\s+/); &nbsp; &nbsp; &nbsp; &nbsp; let character = findObjs({type: 'character', name: args[1]})[0]; &nbsp; &nbsp; &nbsp; &nbsp; if(character){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let weapons = getRepeatingForCharacter(character.id,'attack'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let query = `?{Which weapon|${Object.keys(weapons).map(id =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let nameAttr = weapons[id].find(a =&gt; /_name/i.test(a.get('name'))); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return `${nameAttr.get('current')},%{${character.name}|repeating_weapons_${id}_WeaponCheck}`; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).join('|')}}`; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('SYSTEM', '/w ' + character.name + ' ' + query); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('SYSTEM', '/w ' + msg.who + ' Invalid player'); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } }); const getRepeatingForCharacter = (charID, repeatingName) =&gt; { const matcher = new RegExp(`^repeating_${repeatingName}_-[^_]+_WeaponName`,'i'); return findObjs({ type: 'attribute', characterid: charID }).filter((a)=&gt;matcher.test(a.get('name'))); };
1587042169

Edited 1587042312
The Aaron
Roll20 Production Team
API Scripter
Whoops!&nbsp; That's got a bug in it.&nbsp; Should be: const getRepeatingRowsForCharacter = (charID, repeatingName) =&gt; { const matcher = new RegExp(`^repeating_${repeatingName}_(-[^_]+)_`,'i'); return findObjs({ type: 'attribute', characterid: charID }).filter((a)=&gt;matcher.test(a.get('name'))) .reduce((m,a)=&gt;{ let match = a.get('name').match(matcher); m[match[1]]=m[match[1]]||[]; m[match[1]].push(a); return m; },{}); };
1587042341
The Aaron
Roll20 Production Team
API Scripter
(edited)
Thank you very much for the answer! I understand it a little bit better now and no "critical" errors occurred. Now I get a kind of an array, but undefined (I copy just the beginning): {"undefined":[{"name":"repeating_weapons_-M4Yh2eFaDFBWl8B-Zzw_weaponname","current": BTW: I have to study the regular expressions, they look amazing!
1587046781
The Aaron
Roll20 Production Team
API Scripter
Try putting this in after the let match= line and see what gets logged: log(match); Paste it back here and we can figure out what the issue is.
match works: ["repeating_weapons_-M4Yh2eFaDFBWl8B-Zzw_weaponname"] ["repeating_weapons_-M4Yh7iWFrL8nUu0-sbW_weaponname"] ["repeating_weapons_-M4t96CwNB42iJJVjZ9L_weaponname"] ["repeating_weapons_-M4t98aBUBLI-Lz1NCcb_weaponname"] ["repeating_weapons_-M4t9AQ3YK5DW2ZV4cEd_weaponname"] but the returned value is: {" undefined ":[{"name":"repeating_weapons_-M4Yh2eFaDFBWl8B-Zzw_weaponname","current":"Spadone a due mani","max":"","_id":"-M4Yh45Kg96Tkw-NdtZy","_type":"attribute","_characterid":"-M4YgQPT1BO6mUphEVe-"},{"name":"repeating_weapons_-M4Yh7iWFrL8nUu0-sbW_weaponname","current":"Arco Lungo","max":"","_id":"-M4Yh8qMF91ArPwsOXfK","_type":"attribute","_characterid":"-M4YgQPT1BO6mUphEVe-"},{"name":"repeating_weapons_-M4t96CwNB42iJJVjZ9L_weaponname","current":"Artiglio2 ","max":"","_id":"-M4t98KzU-f1h2X_zBHH","_type":"attribute","_characterid":"-M4YgQPT1BO6mUphEVe-"},{"name":"repeating_weapons_-M4t98aBUBLI-Lz1NCcb_weaponname","current":"Artiglio3 ","max":"","_id":"-M4t9A8YlH2zRcXybiKm","_type":"attribute","_characterid":"-M4YgQPT1BO6mUphEVe-"},{"name":"repeating_weapons_-M4t9AQ3YK5DW2ZV4cEd_weaponname","current":"Artiglio4 ","max":"","_id":"-M4t9C-J16RMFQ8aCx4O","_type":"attribute","_characterid":"-M4YgQPT1BO6mUphEVe-"}]}
1587049222
The Aaron
Roll20 Production Team
API Scripter
That's really bizarre. I'll have to try it tonight in the api.&nbsp; I tried a quick version in a javascript console and it worked right for the above names.&nbsp; For some reason, it seems like the capturing group isn't capturing in the API.
1587051127

Edited 1587051259
No idea. Thank you very much for your help. The problem is intriguing me, but I am not sure I am currently understanding the "reduce" part (not the idea, the implementation). I am trying another solution, less elegant but that I'm able to understand. Looks working: this.getRep = function(charID,repGroup,repName) { var character, weaponIDs; character = getObj('character', charID); &nbsp;&nbsp;&nbsp;&nbsp;weaponIDs = filterObjs(function(obj) { &nbsp;&nbsp;&nbsp;&nbsp;if(obj.get("type") === 'attribute' &amp;&amp; obj.get('characterid') === character.id &amp;&amp; (obj.get('name').indexOf(repGroup) &gt; -1) &amp;&amp; (obj.get('name').indexOf('_'+repName) &gt; -1)) return true; else return false; &nbsp;&nbsp;&nbsp;&nbsp;}); return(weaponIDs); } P.S. It is a member or my "utility" class, I made it generic for all my repeating items, for this reason I have more parameters
1587084564
The Aaron
Roll20 Production Team
API Scripter
Hmm... I just tried this in one of my own games and it worked fine.&nbsp; Very weird..
No idea, but I saw strange things while learning how to code in roll20, but I must admit that I've never programmed in Java before and I'm no longer a developer since... mmm, about 2001, I'm quite rusty :) Thank you for your answers and for showing me the existence of regular expression I've never used before.&nbsp;
1587127890
The Aaron
Roll20 Production Team
API Scripter
No problem!&nbsp; When you're looking for more information on it, it's Java SCRIPT . It shares some minor syntactical elements with Java, but is completely different in most ways.&nbsp; Annoying that the names are so similar, but that's what we've got. =D&nbsp; &nbsp;It's also called ECMAScript officially, which is were various standards like ES6 and ES2017 get their ES from.