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

Getting the current side of a token via the api. How?

I need to “get” the current side of a token that is a rollable table. I use it to show command points in a SWN campaign. I’ll need that to run a true/false Boolean of whether there are enough commandPoints to do a player action.   Adjusting what the current side is with token-mod is simple. But getting the current side has me scratching my head.  I tried using the Fetch script, but it doesn’t want to work.  If anyone can show me how to do that with a known tokenID I’d be grateful and appropriately humbled. I just want to use it in declaring a const    Is there a .get for this attribute? That would be easiest, but I’ve dug through page after page with no luck. 
<a href="https://app.roll20.net/forum/post/10005732/meta-script-fetch-retrieve-attributes-repeating-attributes-abilities-or-token-properties/?pageforid=10151776#post-10151776" rel="nofollow">https://app.roll20.net/forum/post/10005732/meta-script-fetch-retrieve-attributes-repeating-attributes-abilities-or-token-properties/?pageforid=10151776#post-10151776</a> @(selected.currentside) Should get you what you want. !/w gm @(selected|character_name) token side is currently @(selected.currentside).{&amp;simple} If you have the TokenID then you'd just need to replace both 'selected' with that TokenID.
1728323105
timmaugh
Pro
API Scripter
What do you mean Fetch didn't want to work? And is this a Jumpgate game? I just tested all of these in my legacy game and they work. These assume you have the Metascript Toolbox installed. To test them yourself, just wrap them in: ! ... {&amp;simple} Current side (0-based, data as stored in Roll20) : @(selected.side) Current side (1-based, i.e., what TokenMod uses : {&amp;math @(selected.side) + 1} Current side (1-based, option 2)&nbsp; : {&amp;r}@(selected.side) + 1{&amp;/r} Getting the name of the side from the source rollable table :&nbsp;@\(table.SourceTableName.@(selected.side)) Fetch will return that value to the command line of a bangsy message... meaning it will be there when a command line for TokenMod passes through. Fetch will update the message with the resolution of the Fetch syntax. That's why we start with a bang (!). If you want to *see* the result, you have to change the message back into a non-bangsy message (or a "simple" message), which is why we use the {&amp;simple} tag. Without that, the message continues on to the stack of installed scripts as if expecting one of them is going to do somethign with the message. So try the above formations for whatever piece of data you're looking for. If they don't work, let me know. Or, if you don't see the piece of data you're looking for, let me know that, too.&nbsp;
1728323179
timmaugh
Pro
API Scripter
Ha! Well ninja'd, Jarren. Well ninja'd, indeed. =D
1728323885

Edited 1728324167
GM
Pro
Not jumpgate. I’m sure Fetch works well, I’m just having a syntax issue or maybe some sort of scoping issue, or a bad call… probably syntax? my use-case it programmatic. I’ll use this value to compare to another integer in my script &nbsp; So can i do this? &nbsp; const currentCmdPts = @(-4i4hdu3idj3eiwj3|currentside) +1; or… const currentCmdPts =&nbsp; {&amp;math @(- 4i4hdu3idj3eiwj3. side) + 1} I made up the tokenID since I’m not near my dev machine
1728325823
timmaugh
Pro
API Scripter
OH! Fetch works from the CLI within the game (the Chat input). If you want to get it from the script side, you have to use the JavaScript syntax. Assuming you have something like this for getting a token: &nbsp; &nbsp; const getToken = (info, pgid = '') =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; let token = findObjs({ type: 'graphic', subtype: 'token', id: info })[0] || &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; findObjs({ type: 'graphic', subtype: 'card', id: info })[0] || &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; findObjs({ type: 'graphic', subtype: 'token', name: info, pageid: pgid })[0] || &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; findObjs({ type: 'graphic', subtype: 'token', pageid: pgid }) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .filter(t =&gt; t.get('represents').length &amp;&amp; findObjs({ type: 'character', id: t.get('represents') })[0].get('name') === info)[0]; &nbsp; &nbsp; &nbsp; &nbsp; return token; &nbsp; &nbsp; }; You can do something like: let token = getToken(` 4i4hdu3idj3eiwj3`); if (!token) { &nbsp; // handle whatever reporting you want to do &nbsp; // return; } let&nbsp; currentCmdPts &nbsp;= token.get('currentSide') || 0;
1728327039
timmaugh
Pro
API Scripter
BTW, the depending on what you want to do, the metascripts can probably do some of these things right in the chat message with TokenMod... Including the conditional. If you want to go route of a custom script, ok .. but if you're already going to use TokenMod, then maybe some of what you want to do can be accomplished without having to build a new script&nbsp; Can you explain what you're trying to do, overall?
Timmaugh, you never fail to impress.&nbsp; So… I’m GMing Stars Without Number, and the game uses Command Points for space combat. I have a rollable table token i use to show the players their current command points.&nbsp; When they attempt an action, it costs command points. I want to do a checker when they use one of these actions (all actions are in api scripts). If the points for the action are greater than the current command points, i want to sendChat to the players that there aren’t enough points for that action, and exit that script without performing the action. &nbsp; As I store those command points in the rollable table (side 1 is 1point, side 5 is 5points, etc), I’d need to reference what the current side of the token is to do the check.&nbsp;
1728348218
timmaugh
Pro
API Scripter
Given an existing script command like: !modbattr --charid -M1234567890abcdef --SpectralCarp|[[1d10]] ...which would raise the SpectralCarp attribute on that character by a d10 (bounded to within the max value)... ...then you can employ the metascript toolbox to handle the conditional (and the check of the Command Points token. Let's assume that you name the multi-sided token for the command points "Command Points". Let's also assume that you know the above command should only run if the Command Points token shows at least 8. A simple "if there are enough command points modify the SpectralCarp; otherwise do nothing" command would be: !{&amp;if {&amp;math @(Command Points.side) + 1} &gt;=8}modbattr --charid &nbsp; -M1234567890abcdef --SpectralCarp|[[1d10]]{&amp;end} If you wanted to give a message when they tried to run the command without enough points, you could modify the above to include an ELSE case: !{&amp;if {&amp;math @(Command Points.side) + 1} &gt;=8}modbattr --charid &nbsp; -M1234567890abcdef --SpectralCarp|[[1d10]] {&amp;else}{&amp;template:default}{{name=Not Enough Command Points}} {{You do not have enough points for that action.}} {{ Required Points=8}}{&amp;simple}{&amp;end} If you can't see from those examples how to convert your own commands, post them and I can help.
This does the trick for sure. Your earlier example got me out of trouble, but this is so much more efficient.&nbsp;