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

Flight API problem

1624721385

Edited 1624721466
Flight API refuses to work when the token on the map is from a card hand.  I've tried setting the decks cards as tokens and not tokens in their settings but no matter what flight api refuses to function on them.   Alternatively, I'm only using flight API on cards to denote multiples so if anyone has another method of doing that with a simple script that'd be cool.  Flight is the only way I know to easily go over 9.  
1624768613
The Aaron
Roll20 Production Team
API Scripter
Try my Flymore script:&nbsp; <a href="https://app.roll20.net/forum/permalink/9888181/" rel="nofollow">https://app.roll20.net/forum/permalink/9888181/</a> It should work with any graphic, including cards.&nbsp;
It seems to only work when the card has been placed for a really long time.&nbsp; It fails just like Flight API.&nbsp; Right now in my session I can't apply the values to any card.&nbsp; But I know for a fact when I first swapped in it, it worked on a card.&nbsp; No error message, the card just recieves no symbols or values.&nbsp;&nbsp;
1624904793
The Aaron
Roll20 Production Team
API Scripter
Ah, you're right!&nbsp; Try this version: on('ready', () =&gt; { const upStatus = 'green'; const groundStatus = 'blue'; const downStatus = 'red'; const decomposeStatuses = (statuses) =&gt; statuses.split(/,/).reduce((memo,st,idx) =&gt; { let parts=st.split(/@/); let entry = { mark: parts[0], num: parseInt(parts[1],10), idx: idx }; if(isNaN(entry.num)){ entry.num=''; } if(entry.mark.length) { memo[entry.mark] = ( memo[entry.mark] &amp;&amp; memo[entry.mark].push(entry) &amp;&amp; memo[entry.mark]) || [entry] ; } return memo; },{}); const composeStatuses = (statuses) =&gt; Object.keys(statuses).reduce((m,k) =&gt; { statuses[k].forEach((sd)=&gt;m.push(sd)); return m; },[]) .sort((a,b)=&gt;a.idx-b.idx) .map( (s) =&gt; ('dead'===s.mark ? 'dead' : ( s.mark+(s.num!=='' ? '@'+s.num : ''))) ) .join(','); const statusSetter = (op) =&gt; { let applyOp = (e) =&gt; { let n = Math.round(op(e)); if(0 !== n) { return { [n&gt;0 ? upStatus : downStatus]: n.toString() .split('') .filter(c=&gt;/\d/.test(c)) .map((c,i) =&gt; ({ mark: (n&gt;0 ? upStatus : downStatus), num: c, idx: 10000+i })) }; } return {[groundStatus]:[{mark:groundStatus,num:'',idx:10000}]}; }; const clean = (sm) =&gt; { delete sm[downStatus]; delete sm[groundStatus]; delete sm[upStatus]; return sm; }; const getElevation = (sm) =&gt; { let accum=0; let marks = [upStatus,downStatus,groundStatus]; let mark = marks.find(s=&gt;sm.hasOwnProperty(s)); let dir = (mark === downStatus) ? -1 : 1; if(mark){ sm[mark].find(e=&gt;{ if(Number.isInteger(e.num)){ accum*=10; accum+=e.num; return false; } return true; }); } return dir*accum; }; const set = (sm,e) =&gt; ({...sm,...applyOp(e)}); return (t) =&gt; { let sm = decomposeStatuses(t.get('statusmarkers')); let e = getElevation(sm); t.set({ statusmarkers: composeStatuses(set(clean(sm),e)) }); }; }; const processInlinerolls = (msg) =&gt; { if(msg.hasOwnProperty('inlinerolls')){ return msg.inlinerolls .reduce((m,v,k) =&gt; { let ti=v.results.rolls.reduce((m2,v2) =&gt; { if(v2.hasOwnProperty('table')){ m2.push(v2.results.reduce((m3,v3) =&gt; [...m3,v3.tableItem.name],[]).join(", ")); } return m2; },[]).join(', '); return [...m,{k:`$[[${k}]]`, v:(ti.length &amp;&amp; ti) || v.results.total || 0}]; },[]) .reduce((m,o) =&gt; m.replace(o.k,o.v), msg.content); } else { return msg.content; } }; const getChangeOp = (change) =&gt; { const ops = { '+': (a,b)=&gt;a+b, '-': (a,b)=&gt;a-b, '/': (a,b)=&gt;a/(b||1), '*': (a,b)=&gt;a*b, '!': (a,b)=&gt;(a?0:b), '=': (a,b)=&gt;b }; let txt = `${change}`; let op = (ops.hasOwnProperty(txt[0]) ? txt[0] : "="); let num = parseInt(txt.slice((txt[0]===op) ? 1 : 0)); return (n)=&gt;ops[op](n,num); }; on('chat:message',msg=&gt;{ if('api'===msg.type &amp;&amp; /^!fly(\b\s|$)/i.test(msg.content) ){ let who = (getObj('player',msg.playerid)||{get:()=&gt;'API'}).get('_displayname'); let args = processInlinerolls(msg).split(/\s+/); if(args.length &lt; 2) { sendChat('fly', `/w "${who}" &lt;div&gt;&lt;b&gt;Usage:&lt;/b&gt; &lt;code&gt;!fly [NUMBER]&lt;/code&gt; with tokens selected. &lt;code&gt;NUMBER&lt;/code&gt; can be prefaced with an operation from among: &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, or &lt;code&gt;=&lt;/code&gt;. Prefacing with an operation will make a relative change, for example, &lt;code&gt;!fly -20&lt;/code&gt; will reduce the selected token elevation by 20. Note: to explicitly set a negative elevation, preface with &lt;code&gt;=&lt;/code&gt;, for example, &lt;code&gt;!fly =-20&lt;/code&gt; will set the elevation to -20 no matter where it is currently.&lt;/div&gt;`); return; } let op = getChangeOp(args[1]); let tokens = (msg.selected || []) .map(o =&gt; getObj('graphic',o._id)) .filter(t =&gt; undefined !== t) ; let ss = statusSetter(op); tokens.map(ss); } }); });