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

Can I use an API to call/move a token to another token?

1747831829

Edited 1747831923
Can I use an API to call/move a token to another token? I’m trying to use a token as a starting point indicator of a player move.   I was thinking something like a call to Thor’s Hammer. This way a player could start their move, and have a specific token called to their location, so the player would have a reference as to the starting point. Ideally the token could be resting on the Map Layer and when called, it would be moved to the location… on the map layer. Only 1 of these tokens would be needed. And as the other players begin their moves, that same token would again, be call to assist them.   Now if the Map Layer bit is a bridge too far… staying on the Token Layer would still be very helpful. Any help or suggestions would be wonderful. Thx.
1747834218
timmaugh
Forum Champion
API Scripter
Yes, TokenMod combined with the Metascript Toolbox can do this. To move a token named "StartingPosition" (which is on the map layer) to be at the location of the currently selected token, you'd run: !token-mod --ids @(StartingPosition.token_id) --set top|@(selected.top) left|@(selected.left) For your *players* to be able to run this command you will need to configure TokenMod to allow them to use IDs. You can find that setting either on the Script Deck page for TokenMod in your game (if you installed TokenMod from the one-click), or you can find the "playerscanuseids" setting in the help to see the command line operation. Also, just to be on the safe side, you will want to configure SelectManager (one of the metascripts in the toolbox), as well. To do that, run this command one time in your game: !smconfig +playerid +who Then you should be golden. Alternatively If you don't put the "StartingLocation" token on the map layer, you won't have to configure TokenMod to let players use ids. You *could* plut the token on the token layer, but just don't give players the ability to select it (so they don't inadvertently move it). To them, it will still operate/look/feel the same. In that case, your command line could become: !token-mod --set top|@(@{selected|token_id}.top) left|@(@{selected|token_id}.left) {&select StartingPosition} Again, that would move the StartingPosition token (which is on the token layer) to be co-positioned with the selected token. Note, if there is a size discrepancy between the StartingPosition token and the "calling" token, you could do math involving the height/width of the tokens to position the centers rather than the top left corners. Alternate-Alternatively If *only* the GM needed to call the command, that could be done both without configuring TokenMod AND without needing the token on the token layer (it could still be on the map layer). The command would still require selecting the player token (i.e., where you want Starting Position to move to), but it would look like this: !token-mod --set top|@(@{selected|token_id}.top) left|@(@{selected|token_id}.left) {&select StartingPosition, +layer=map} Or you could do it by targeting the player token (where you want StartingPosition to move to) like this: !token-mod --set top|@(@{target|token_id}.top) left|@(@{target|token_id}.left) {&select StartingPosition, +layer=map} So, lots of options.
1747836669

Edited 1747836691
      Hey, thx for replying... but i was unable to get it to work. I am currently already using TokenMod… Great API (ChatSetAttr as well… love them both), Here is what I did: 1)      Made a Token and called it “StartingPosition” place in on the Token Layer. 2)      Made sure TokenMod was running properly, 3)      Then selected a another Token and pasted in the code:   !token-mod --set top|@(@{selected|token_id}.top) left|@(@{selected|token_id}.left) {&select StartingPosition}   4)      I hit enter, and Nothing Happen.
1747838189
timmaugh
Forum Champion
API Scripter
Did you install the Metascript Toolbox, too?
no... thought you said i did not need to if i was not putting it on the Map layer.... I will load it now.
MetaScriptToolbox or it's dependencies read or write fields that are used by other scripts you currently have installed. There is a possibility that these scripts might conflict with each other. Would you like to continue the installation? I am running these Scripts TokenMod Teleport ChatSetAttr RecursiveTable Do you know what  confliction?
1747839135

Edited 1747839205
OOoooooooo! Oooo it worked!... the Devil be damned!... I'll risk it!.... THANK YOU!
1747839352
timmaugh
Forum Champion
API Scripter
Yeah, no worries about that conflict statement. The "conflict" detection is an "opt-in" system for announcing what your script does... but not many people opt-in. You're good to use it without fear.
thx again!!!!!   I will jump into that script... and see what else i can do with it! THANK YOU!
1747840888
timmaugh
Forum Champion
API Scripter
Happy to help. BTW, the Toolbox is a bit esoteric in that it helps other scripts do things (or for you to do things not normally available via straight Roll20 syntax)... it's a bit much to get into any one aspect of it. For an example of what the scripts of the toolbox can do, here is a list of bookmarks I keep of places where I've helped someone do something in the forums: So, chances are good that if you want to do something and Roll20 isn't allowing you to do it "out of the box", like moving this "StartingPosition" token, the Toolbox can help. If you want someplace to start, I'd suggest this video discussing what makes metascripts different from normal scripts.
1747843050
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Even if you aren't planning on writing any metascripts, that first part of that video is very good for explaining scripts in general.
I LOVE R20!  Thank you both! :)