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 .
×
Advertisement Create a free account

Using the "token_id" from TokenMod

1627254950
Hi, as seen from this post, you can't hard-code token id's inside a Macro Is it still a thing ? :/
1627258309
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You can hard code a token's id in a macro. It's just that every token has a unique id. If you copy and paste or drag a new token onto the VTT, it has a new token id. You cannot easily make a token id that refers to a class of token, such as "the first instance of a token representing the character named Bob" without the API. It might help to know exactly what goal you are trying to achieve. There are some clever folks who might be able to suggest a workaround.
1627275888
Kinji said: Hi, as seen from this post, you can't hard-code token id's inside a Macro Is it still a thing ? :/ The only time I ran into this problem it was in an effort to setup a bunch of macros that call player sheets, so I took 10 total blank tokens and put them on my DM system page.  Assigned each token to a players sheet and then got those token ID's to pump into various api's that can take a token_id as their reference.  Great for snap perception/investigation, and getting the ac/passive of the party playing.  Everytime you make a token, either dragging out or copy/paste it is a new unique token ID in that session.  Theres just no way to lock it down sadly.  
1627280272
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
To be fair, you wouldn't want to. Everything in Roll20 has a unique ID. Every character, token, handout, piece of art or drawing. If it didn't, the API would have a terrible time referencing what you want it to reference.
1627309513
timmaugh
Pro
API Scripter
If you drag a character's token out to a page, but then the party moves on to a different map so you have to drag another token for that player, those are going to have different IDs. That's where something like what Keith said (finding the first token that represents Bob on this page) can be beneficial. Some API scripts will do that natively (you give it "Bob" and it will find the first Bob it comes to on the current page), but if you want something universal the Fetch script can help. Fetch is a metascript -- so it will work in the command lines of other scripts, or it can work in normal chat messages (provided you have API access). The Fetch construction syntax is pretty similar to standard Roll20 syntax. In Roll20 you might need to do: @{selected|token_id} or @{target|token_id} In Fetch, those curly braces become parentheses, and the vertical bar can be either a vertical bar or a period: @(selected.token_id) You can also include a default value if the thing-you-are-asking-for isn't found. Put the default value in brackets as the last thing inside the parentheses: @(selected.token_id[No token ID was found.]) Now, while Fetch can't trigger the targeting reticle, it can do other cool things... like the default value above. It can also use "speaker" as the source of the thing you want to return: @(speaker.token_id) It can find a token by name: @(Bob.token_id) It can return any token property: @(Bob.left) ...or a character attribute: @(Bob.Dexterity) In fact, it can tell whether you are looking for a character attribute or a token property, so it can differentiate either the token named Bob or the character. It can also return repeating items, abilities, or macros, but those are a little afield from the OP's request.
1627321271
Damn, Fetch seems to be the thing I need ! For reference, what I made is a macro to let the player turn on/off his flashlight, but I don't want him to need to select his token before doing that Considering they will never have more than 1 token to control, putting in their macro a hard coded token_id would be the fix I'll try with Fetch, thanks !
1627323541
timmaugh
Pro
API Scripter
Ah, so one other thing to consider is that sometimes a script might not give you a place to provide the ID of a token... sometimes the script is just hard-coded to look for the currently selected token(s). TokenMod is a script that does let you provide the ID, provided you have configured the players-can-ids setting properly. For other scripts, you can also/alternatively make use of SelectManager... that lets you virtually select a token for the purposes/duration of a message. Nothing changes on the tabletop, but the message recognizes particular tokens as being selected (instead of what is selected on the tabletop, or in addition to the tokens selected on the board -- depending on how you use it). {& select Bob} SelectManager's central purpose is to restore selected tokens to api-generated messages (where a script launches a message that calls another script), or when you use a targeting statement.