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

[Script Update] TokenMod -- An interface to adjusting properties of a token from a macro or the chat area.

April 09 (7 years ago)
I am getting a crashing sandbox with this error:

For reference, the error message generated was: TypeError: update.match is not a function
TypeError: update.match is not a function
at getRelativeChange (apiscript.js:6412:19)
at apiscript.js:6787:68
at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9)
at apiscript.js:6774:8
at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:158:9)
at applyModListToToken (apiscript.js:6750:5)
at apiscript.js:7093:25
at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9)
at _.(anonymous function) [as each] (/home/node/d20-api-server/node_modules/underscore/underscore.js:1496:34)
at handleInput (apiscript.js:7092:22)

The macro being used:

!token-mod --set statusmarkers#?{Status|
Disadvantaged,red|
Advantaged,green|
Concentrating,blue|
Readying,stopwatch|
―, |
Prone,back-pain|
Restrained,fishing-net|
Grappled,grab|
―, |
Incapacitated,interdiction|
Stunned,pummeled|
Unconscious,sleepy|
Dying,skull|
―, |
Charmed,chained-heart|
Frightened,screaming|
―, |
Poisoned,half-heart|
Blinded,bleeding-eye|
Deafened,lightning-helix|
Paralyzed,padlock|
Petrified,broken-skull|
―, |
Dodging,bolt-shield|
Cover (half),broken-shield:2|
Cover (three-quarters),broken-shield:5|
Cover (full),white-tower|
Invisible,ninja-mask|
―, }
/w gm &{template:default} {{name=?{Status}
[–](!token-mod --set statusmarkers#?{Status}:-1)[+](!token-mod --set statusmarkers#?{Status}:+1)[#](!token-mod --set statusmarkers#?{Status}:?{Number|1|2|3|4|5|6|7|8|9|None,-9}) [Toggle](!token-mod --set statusmarkers#!?{Status}) [Clear All](!token-mod --set statusmarkers#=red#-red)}}
April 09 (7 years ago)
The Aaron
Pro
API Scripter
Hi guys, sorry you're running into that problem. Insufficient testing on my part. :(. I'm working on a fix and will have it finished tomorrow.   If you grab an older version and install it manually, it will fix the issue. (There is a bug with selecting an older 1-click version currently. )
April 09 (7 years ago)
The Aaron
Pro
API Scripter
Update v0.8.32 -- Fixed crash for empty auras (and other places that could take a number or empty). Additionally, I've added error handling to prevent future crashes and make crash resolution easier. If a command would have caused a crash, it will now instead output this message as a whisper to the person who executed the command:

The block at the bottom can be copied and pasted into a PM to me (link text goes to my profile). It contains the details of the message that was passed to TokenMod, as well as the callstack that crashed. Those are the two bits of information that I need to track down exactly what happened and fix it.

With this new error handling, it won't crash the API and interrupt the game should there be a problem. Let me know if I can make any improvements to this. I have some ideas that will make it much nicer in the future and even allow other script authors to take advantage of it easily.

Update v0.8.31 -- Fixed bug in multiply and divide logic. (Thanks Craven ., keithcurtis, Gold and others...)

You can grab the latest version here: https://github.com/shdwjk/Roll20API/blob/master/To...
It should hit the 1-Click next week or the week after.
April 09 (7 years ago)
Thanks for the quick fix Aaron!
April 09 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Wow, that's elegant error handling!
April 09 (7 years ago)
The Aaron
Pro
API Scripter
Thanks!  It will be even better in the future!  =D
April 11 (7 years ago)
I found part of the macro below and edit it to do what I want using token-mod.
so it rolls the appropriate dice for the healing potions selected and adds the health back to the selected token.
How can i show the number rolled?


&{template:npcaction} ?{Type| Healing, {{rname=Potion of Healing}} {{name=**@{Selected|character_name} is healed.**}} {{r1=[[ {@{target|Target|bar1}+2d4+2, @{target|Target|bar1|Max}d1}kl1]]}}

!token-mod --set bar1_value|[[{@{target|Target|bar1}+2d4+2, @{target|Target|bar1|Max}d1}kl1]] --ids @{target|Target|token_id}  | Greater, {{rname=Greater Potion of Healing}} {{name=**@{Selected|character_name} is healed.**}} {{r1=[[ {@{target|Target|bar1}+4d4+4, @{target|Target|bar1|Max}d1}kl1]]}}

!token-mod --set bar1_value|[[{@{target|Target|bar1}+4d4+4, @{target|Target|bar1|Max}d1}kl1]] --ids @{target|Target|token_id} | Superior, {{rname=Superior Potion of Healing}} {{name=**@{Selected|character_name} is healed.**}} {{r1=[[ {@{target|Target|bar1}+8d4+8, @{target|Target|bar1|Max}d1}kl1]]}}

!token-mod --set bar1_value|[[{@{target|Target|bar1}+8d4+8, @{target|Target|bar1|Max}d1}kl1]] --ids @{target|Target|token_id}| Supreme, {{rname=Supreme Potion of Healing}} {{name=**@{Selected|character_name} is healed.**}} {{r1=[[ {@{target|Target|bar1}+10d4+20, @{target|Target|bar1|Max}d1}kl1]]}}

!token-mod --set bar1_value|[[{@{target|Target|bar1}+10d4+20, @{target|Target|bar1|Max}d1}kl1]] --ids @{target|Target|token_id}}






April 11 (7 years ago)
The Aaron
Pro
API Scripter
At this point, you can't.  That's something I want to fix, but haven't gotten around to yet...
April 12 (7 years ago)

Edited April 12 (7 years ago)
Hey Aaron, do you have any idea why this macro is adding 2 stopwatches to one Character but just 1 to the other tokens?

!token-mod --set statusmarkers|stopwatch[2] --ids @{selected|character_id}

To be clear, Im using this to represent a caster concentrating on a spell, So if they attempt to cast another spell that requires concentration it will add a second stopwatch. The character in question is getting 2 right off the bat (while the others are just getting 1).

Could I have another character on another page interfering with this (Again.. lol). I've searched but can't find any in the 800 Storm King Thunder maps.

Any thoughts?
April 12 (7 years ago)

Edited April 12 (7 years ago)
Joe
Pro
Hi Aaron, thank you very much for sharing these excellent scripts with us, and the active support on them!

I've got a player with a sword that lights on fire when he hits something, then goes out 3 rounds later. I've set up this macro called SwordFed:
!token-mod --set statusmarkers|all-for-one:3
!flicker-on 40 20 yes

That works great except that the flicker doesn't follow the token, and I hope that has to do with my running it on a browser on my iPad, and it will work fine once I get a chance to try it on my computer.

I've got another macro called SwordBurn:
!token-mod --set statusmarkers|all-for-one:-1
And one called SwordOff:
!token-mod --set statusmarkers|-all-for-one
!flicker-off

What I really want is to combine those last two, i.e. take the icon off and turn off the flicker if it has reached 0. Do you know of any way to do that via macro or your script? I've gone over the help and the forum posts, but maybe I've missed it somewhere.

Thank you again!

Joe
April 12 (7 years ago)
The Aaron
Pro
API Scripter
Dustin, the [2] syntax references the second stopwatch. In the absence of a first, it should set the first. I'll have to look at it tomorrow and see what's going on. 

Joe, I'm pretty sure there's  a syntax for that, try:
!token-mod --statusmarkers|?all-for-one:-1
turning the flicker off would need to be a separate thing though. 
April 12 (7 years ago)
Joe
Pro

The Aaron said:

Joe, I'm pretty sure there's  a syntax for that, try:
!token-mod --statusmarkers|?all-for-one:-1
turning the flicker off would need to be a separate thing though. 

Yep, that was it, thanks again!

Regarding calling the other macro, is there any way to do conditional logic in macros?  And return a value from your script based on checking an existing status if there is? 

April 12 (7 years ago)
The Aaron
Pro
API Scripter
There isn't.  Logic is the purview of the API.  I think if you add this above case '!flicker-off':  (about line 369), it should let you do what you want:
            case '!ficker-off-with-status':
                if((args[1]||'').match(/^(--)?help$/) || ( !_.has(msg,'selected') && args.length < 2)) {
                    showHelp(who);
                    return;
                }
                let status=args[1];
                args.splice(1,1);

                if(playerIsGM(msg.playerid)) {
                    objs=_.chain(args)
                    .rest(1)
                    .uniq()
                    .value();
                }
                objs=_.union(objs,_.pluck(msg.selected,'_id'));
                objs=_.reduce((m,id)=>{
                    let o=getObj('graphic',id);
                    if(o && !o.get(`status_${status}`)){
                        m.push(id);
                    }
                },[]);
                _.each(state.Torch.flickers, function(f) {
                    if( _.contains(objs, f.parent)) {
                        clearFlicker(f.id);
                    }
                });
                break;
I've not tested it, but you should be able to put in this:
!token-mod --statusmarkers|?all-for-one:-1
!flicker-off-with-status all-for-one
and have it turn off only when the token doesn't have that status.

April 12 (7 years ago)
I had some crashing API again on last night's session, I believe it was triggered by this Tokenmod macro, but not 100% sure.

Macro:
!token-mod {{
--set
light_radius|60
light_dimradius|30
--on showplayers_bar1
}}

Error:
For reference, the error message generated was: TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at Object.processRolls (apiscript.js:7906:39)
at Object.processRolls (apiscript.js:7913:17)
at handleChatMessage (apiscript.js:8237:13)
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:146:1), <anonymous>:65:16)
at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:146:1), <anonymous>:70:8)
at /home/node/d20-api-server/api.js:1510:12
at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)



April 12 (7 years ago)
Joe
Pro
Thanks, Aaron!  I'll definitely try that.

I've only used the one-click install so far for scripts. Is there an easy way to modify one of those, or do I need to disable it, create a new custom script, and copy/paste your full script code plus the above addition into it?
April 12 (7 years ago)
The Aaron
Pro
API Scripter
If you select a 1-click version of a script, there's a button at the bottom that will copy the source into a tab.. don't remember what it's called, but it should be obvious when you look at them.
April 12 (7 years ago)
Joe
Pro
Thanks again!  I'll look for that when I get back to my computer. 
April 12 (7 years ago)
The Aaron
Pro
API Scripter

Arno said:

I had some crashing API again on last night's session, I believe it was triggered by this Tokenmod macro, but not 100% sure.

Macro:
!token-mod {{
--set
light_radius|60
light_dimradius|30
--on showplayers_bar1
}}

Error:
For reference, the error message generated was: TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at Object.processRolls (apiscript.js:7906:39)
at Object.processRolls (apiscript.js:7913:17)
at handleChatMessage (apiscript.js:8237:13)
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:146:1), <anonymous>:65:16)
at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:146:1), <anonymous>:70:8)
at /home/node/d20-api-server/api.js:1510:12
at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)




That's actually not in TokenMod.  It's probably either in HiddenRolls, TrackerJacker, or CreatureGen, though I don't see a processRolls function in any of them.  What else do you have installed?

April 12 (7 years ago)
Powercards. Of course. I'm the bane of everyone apparently.
April 12 (7 years ago)

The Aaron said:


That's actually not in TokenMod.  It's probably either in HiddenRolls, TrackerJacker, or CreatureGen, though I don't see a processRolls function in any of them.  What else do you have installed?


Hmm ok, well I run these:

GroupInitiative
TurnMarker
G Vector Math
G MatrixMath
G Path Math
G Torch
ApplyDamage
TokenMod
No Token Rotation
RollStats
HealthColors
Calendar
G Dynamic Light Helper
TableExport
5eShapedCompanion
RecursiveTable
GroupCheck
ChatSetAttr
TokenNameNumber

Perhaps GroupInitiative then?

April 12 (7 years ago)

Arno said:

The Aaron said:


That's actually not in TokenMod.  It's probably either in HiddenRolls, TrackerJacker, or CreatureGen, though I don't see a processRolls function in any of them.  What else do you have installed?


Hmm ok, well I run these:

GroupInitiative
TurnMarker
G Vector Math
G MatrixMath
G Path Math
G Torch
ApplyDamage
TokenMod
No Token Rotation
RollStats
HealthColors
Calendar
G Dynamic Light Helper
TableExport
5eShapedCompanion
RecursiveTable
GroupCheck
ChatSetAttr
TokenNameNumber

Perhaps GroupInitiative then?


Disable all except token mod as that is the macro you are running. If no error turn on one at a time until you get the error


April 13 (7 years ago)
The Aaron
Pro
API Scripter

Sky said:

Powercards. Of course. I'm the bane of everyone apparently.
Nah, you have "processroll", this is "processRolls".

April 13 (7 years ago)
The Aaron
Pro
API Scripter

Arno said:

The Aaron said:


That's actually not in TokenMod.  It's probably either in HiddenRolls, TrackerJacker, or CreatureGen, though I don't see a processRolls function in any of them.  What else do you have installed?


Hmm ok, well I run these:

GroupInitiative
TurnMarker
G Vector Math
G MatrixMath
G Path Math
G Torch
ApplyDamage
TokenMod
No Token Rotation
RollStats
HealthColors
Calendar
G Dynamic Light Helper
TableExport
5eShapedCompanion
RecursiveTable
GroupCheck
ChatSetAttr
TokenNameNumber

Perhaps GroupInitiative then?


It's not in any of my scripts or in the any of the repo scripts, I just grepped all the source.
April 13 (7 years ago)
It's likely RollStats or ApplyDamage then just guessing on names.
April 13 (7 years ago)
Thanks both for investigating. I have disabled Rollstats for now to test. I was certainly not using ApplyDamage at the time of the crash. But not sure if that's needed for it to crash.
April 13 (7 years ago)
The Aaron
Pro
API Scripter
Every on('chat:message',...) chat handler will get called for every message, so if it makes certain assumptions, it can break.  The 29 scripts I updated a few weeks ago were fixes for the assumption that a human was going to call the command.  They would all break whenever an api script executed a command, but not necessarily the command that they serviced.
The image swap part of this API can I use it simply to change my token to an imagine of it being in a down state?  For instance I have a standing topdown, when I hit 0 hp and also have an image of it in a prone state, can I simple run the image swap macro to replace the image?  Then of course one for being up?  Cause thats what it sounds like.
April 13 (7 years ago)
The Aaron
Pro
API Scripter
Yes, with the caveat that the API can only create images that are in user Libraries, so you'd need the URL in your user library (see my note in the TurnMarker thread about how to get that.)

Another option is to set up a Rollable Table Token and change sides on that in the right click menu of the token.
April 13 (7 years ago)
Joe
Pro
Hi Aaron, is there anywhere the full Help for TokenMod is listed outside of the game, so I can reference it for macro planning when I'm on my phone?  It seems like old or abbreviated versions are on a couple different pages or forum posts, and I get trying to keep it in sync in multiple places is annoying, it would just be helpful to me right now. 
April 13 (7 years ago)
!token-mod --help from the chat windows.
April 13 (7 years ago)
Joe
Pro

Craven . said:

!token-mod --help from the chat windows.

Yes, I'm aware that is the best option, but it isn't readily available when I'm on my iPhone. 
April 13 (7 years ago)
The Aaron
Pro
API Scripter
It is on the 1-click install page when you have it selected, or when you click on the tab where you have it installed from 1-click.  Aside from that, not yet.  I have plans...
April 13 (7 years ago)
Joe
Pro

The Aaron said:

It is on the 1-click install page when you have it selected, or when you click on the tab where you have it installed from 1-click.  Aside from that, not yet.  I have plans...

Ok, that will probably work. Thanks!
April 13 (7 years ago)
When will 0.8.32 be available in the 1-click?

April 13 (7 years ago)
The Aaron
Pro
API Scripter
Probably Tuesday.  Phil was out sick so didn't get it merged this week.
April 13 (7 years ago)
Joe
Pro
Forgive the newbie question, but if I've installed a script via the one-click, does it update automatically to new versions, or do I need to take some action to do so?
It will automatically update.

April 13 (7 years ago)

Joe M. said:

Forgive the newbie question, but if I've installed a script via the one-click, does it update automatically to new versions, or do I need to take some action to do so?

It does but right now if I used the 1 click it loads 0.8.31 that crashes for me so I have manually added 0.8.32 which has all the fixes thanks to Aaron.
April 13 (7 years ago)
Joe
Pro

Gozer the Gozerian said:

It will automatically update.


Fantastic, thanks! 
April 13 (7 years ago)
The Aaron
Pro
API Scripter

Dustin C. said:

Hey Aaron, do you have any idea why this macro is adding 2 stopwatches to one Character but just 1 to the other tokens?

!token-mod --set statusmarkers|stopwatch[2] --ids @{selected|character_id}

To be clear, Im using this to represent a caster concentrating on a spell, So if they attempt to cast another spell that requires concentration it will add a second stopwatch. The character in question is getting 2 right off the bat (while the others are just getting 1).

Could I have another character on another page interfering with this (Again.. lol). I've searched but can't find any in the 800 Storm King Thunder maps.

Any thoughts?
So, I missed initially that this was using the character_id.  I'd forgotten I even added that. =D  What's happening is that by default, TokenMod includes the selected token in the group of tokens to modify (This has a complicated history of working and not working based on if you're using ?{target}, but in your case, it would be included.).  So effectively, you are adjusting the union of:
  • All the tokens that represent the character the selected token represents
  • The selected token.
That means the selected token is adjusted twice, while the other tokens that represent the character are not.  Obviously, that's not what I want it to do. =D 

There are two ways to fix this:
1) I need to push an update that causes it to make the list unique after expanding the tokens a character id represent. (I'm doing this now, push coming shortly)
2) You can add --ignore-selected to your macro to cause it to exclude the selected token for the time being.

Ok. I've pushed version 0.8.34 which fixes this and a few minor bugs with ! and - on [] statuses.



April 13 (7 years ago)
The Aaron
Pro
API Scripter
Update v0.8.34 -- Fixed the behavior of ! and - adjustments to statusmarkers when dealing with [] statuses.

Using - with a [] status will now remove the rightmost instance of that status, rather than all of them.
!token-mod --set statusmarkers|-blue[]
Using ! with a [] status with now toggle on a new copy of that status (just like +blue[] would):
!token-mod --set statusmarkers|!blue[]
And using ! with a [] status and an index will toggle that index of the status on. Note that toggling status indexes that are higher than a set status will cause it to fill the next lowest slot.
!token-mod --set statusmarkers|!blue[3]
Executing this over and over on an empty token will add 1 blue dot each time until there are 3, then subsequently toggle the 3rd one on and off on each execution.

Update v0.8.33 -- Fixed bug where specifying a character_id with --ids while having a token selected that represented that character would cause a double adjustment. (Thanks Dustin C.)
April 16 (7 years ago)

Edited April 16 (7 years ago)
Firstly, I am sorry for showing my ignorance again, I am looking to use tokenmod as part of an APT command button with the following:

/w GM [Fireball](!roll20AM --play|Fireball by kaiju
!token-mod --order toback
!token-mod --set imgsrc|https://s3.amazonaws.com/files.d20.io/images/4095816/086YSl3v0Kz3SlDAu245Vg/max.png?1400535580
!token-mod --set width|560 height|560)

i have escaped the html:
/w GM [Fireball](!roll20AM --play|Fireball by kaiju&#13;!token-mod --order toback&#13;!token-mod --set imgsrc|https://s3.amazonaws.com/files.d20.io/images/4095816/086YSl3v0Kz3SlDAu245Vg/max.png?1400535580&#13;!token-mod --set width|560 height|560)

It wont show but i have also secaped the ? on the url

But the imgsrc seems to kill it, am I missing something, sorry I know I am missing something, but what?
April 16 (7 years ago)
The Aaron
Pro
API Scripter
APT command?

what error are you getting?
April 16 (7 years ago)

Edited April 16 (7 years ago)
Sorry - to get a button in the chat. its like API but at 2am (oops)

There is no error  just will not show the button with the img part left in
April 16 (7 years ago)

Edited April 16 (7 years ago)
The Aaron
Pro
API Scripter
This seems to be a limitation of command buttons.  Here's what I'd suggest (this worked for me):
Create a character named tokenmod and add an ability to it named fireball with this in it:
!roll20AM --play|Fireball by kaiju
!token-mod {{
  --order toback
  --set 
    imgsrc|https://s3.amazonaws.com/files.d20.io/images/4095816/086YSl3v0Kz3SlDAu245Vg/max.png?1400535580
    width|560
    height|560
}}
make your button call that ability like this:
/w gm [fireball](!&#13;&#37;{tokenmod|fireball})
Then your button will show up.

Also, it makes editing the fireball commands easier. =D  You can call the character anything you want, and name the abilities whatever, just so long as you name them right in the button.
April 16 (7 years ago)
!token-mod --set imgsrc| is this a token-mod command. I don't see it in the doc. What is the image for? Spell fx?
April 16 (7 years ago)
The Aaron
Pro
API Scripter
This changes the token's image, so in this case, he is changing to a fireball image.

It's in the help between Status Markers and Character ID:



its for creating the area of effect - so it can stay, for example, the spells spike growth or call lightning, or just for AOE for fireball

but it still does not seem to work:
 first line copied and pasted as above, second with each new line escaped in the ability, sorry
April 16 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hmmm. I wonder if this is a more strightforward way than the one I posted last week. I was using a rollable token. It might be simpler than looking up the URL for each uploaded image.
April 16 (7 years ago)
The Aaron
Pro
API Scripter

Jon M. said:

its for creating the area of effect - so it can stay, for example, the spells spike growth or call lightning, or just for AOE for fireball

but it still does not seem to work:
first line copied and pasted as above, second with each new line escaped in the ability, sorry

Whoops!  The forum ate the HTML entities. I fixed the button code above. You have to have a carriage return symbol ( &#13; ) after the ! and you have to use &#37; instead of % so the macro isn't expanded until the button is clicked.