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

Question about token mod and controlled by

Hi,  I'd like to ask for a target to set control to that target.  I tried this (and the return of the target is correct when put directly in the chat) !token-mod --set controlledby|@{target|token_name} But it actually doesn't set the control of the selected to the targetted...  Am i missing something ? Thx
1672957578
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Lionel! A token cannot control another token. The attribute that goes into the controlledby field has to be a player name, "all players" or a player id. As far as I know, you can't poll the id of a controller (player) though an attribute call. This is probably possible with one of timmaugh's meta scripts, though. If you have a list of players you'd like to be the standard choices however, you could probably handle it with a drop down query. !token-mod --set controlledby|"?(Bob,Bob|Ted,Ted|Carol,Carol|Alice,Alice}" The quotes handle players with spaces in their names.
1672957611

Edited 1672958144
You are trying to set the controlled by of a token to the name of another token, not the name of a player. You would need something like this: !token-mod --set controlledby|?{Who|Name of Player} The TokenMod Help document says: Token ID will be used to collect the controlledby entries for a token or the associated character if the token represetns one. Character ID will be used to collect the controlledby entries for a character. When using Token ID or Character ID methods, it's a good idea to use an explicit operation: !token-mod --set controlledby|=@{target|token_id} But that isn't working for me, so maybe that's something for Aaron to look at.
that's weird as in the edit field, when you're checking the controlled by field, then the dropdown list is the name of the token, no ? Is there a formula to be able to do it with a target ? @{target|player_name} for example ?
1672958885
timmaugh
Pro
API Scripter
First thing going on is you don't have selected tokens when you use a targeting statement, so in that case you're going to have to add an --ids argument to your command, and make sure you're either the GM or that the "players-can-ids" argument is set to allow players to use the --ids argument: --ids|@{selected|token_id} Next, I don't think TokenMod does what you're trying to do the way you're trying to do it... (setting the controlledby property to be the same as the controlledby property of a token you supply). I think you have to supply the players since that is what is stored in the controlledby property. You can get it the controlledby list with Fetch: @(@{target|token_id}.token_cby) However that will be comma-delimited, and the Token-Mod syntax wants pipe-delimited. Fetch doesn't natively produce that, but I could easily write a little 1-off metascript for text replacement... or a plug-in for Plugger that would do that.
1672959027
timmaugh
Pro
API Scripter
If the controlledby is a single player, then the Fetch construction will work on its own. Or if you only want to get the first player in the controlledby list, you can get that with the player (for ID), or player_name (for name) properties: @(@{target|token_id}.player} or @(@{target|token_id}.player_name}
1672959848

Edited 1672960189
Hey timmaugh.  I think there's a little misunderstanding.  I'm selecting a monster's token, and i want to give control of that token to a target (a player). EDIT : I'd Prefer a target than a dropdown list)
1672960661
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
As above, you would need to get the player name or id from the target token. Several of timmaugh's suggestions do just this. Without something like Fetch, this information is not available from a @{target|______} construction. What you are trying to do cannot be accomplished by token-mod alone. Fetch will help you get that information. It's also possible that ScriptCards can do this, but I don't use that script. You could try posting on it's feedback thread.
Ok i understand. I have fetch installed, so what would be the fetch construction then ? !token-mod --set controlledby|= @(@{target|token_id}.player_name} ? that ?
I actually have a related question, can you preselect a token by name via macro before executing additional macro lines which requires a token to be selected?
1672964330
The Aaron
Forum Champion
API Scripter
Hmm.  The TokenID there might be a copy paste error.  Certainly being able to copy the controlled by from an existing token seems like a sensible operation.  I don't see where I implemented that functionality in the past, so perhaps I should do that now.
1672968402
timmaugh
Pro
API Scripter
Lionel V. said: Ok i understand. I have fetch installed, so what would be the fetch construction then ? !token-mod --set controlledby|= @(@{target|token_id}.player_name} ? that ? Exactly... that would get you the name of the first player in the controlled by list... so as an example, that would resolve down to: !token-mod --set controlledby|timmaugh ...by the time Token-Mod saw the command line. This is a way to transfer 1 control to 1 player, which is what I think you want. On the other hand, if there is more than one player in the controlledby list and what you wanted was to duplicate that full list... there is no way to do that (currently), until either Aaron gets it added to TokenMod or I write that plug-in to plugger. Which I'm going to write right now. I've been needing a text replacement metascript for a couple of solutions, now. =D
1673010825
timmaugh
Pro
API Scripter
JP G. said: I actually have a related question, can you preselect a token by name via macro before executing additional macro lines which requires a token to be selected? SelectManager can help with that. {&select Cletus} It doesn't truly select the token (where you have the box/handles on the VTT), but it puts the necessary information into the message object before a script sees it. Since it happens during the script operations phase, you can't then use formations like: @{selected|token_id} ...however, Fetch can get those sorts of properties -- also in the script operation phase and *after* SelectManager: @(selected.token_id) Since this means that you can't use standard Roll20 syntax, your basic messages (those you would just intend to send to the chat rather than the script moderator) also need to begin as script messages (bangsy messages, beginning with an exclamation point). To get an output from one of those kind of messages (allowing metascript processing but not standard script processing), you can use ZeroFrame, and put a {&simple} in the message: !This won't work. !This will work.{&simple} Your token selection will not last between multiple lines of your macro, so each line will need a SelectManager {&select ... } construction, however roll queries DO get replaced across multiple separate lines of a multi-command macro, so you should be fine to construct a query to select the proper token, then re-use that query in your {&select...} constructions in each of your macro lines. Start a new thread if you have questions about that, share your original macro, and I will try to help.
timmaugh said: Lionel V. said: Ok i understand. I have fetch installed, so what would be the fetch construction then ? !token-mod --set controlledby|= @(@{target|token_id}.player_name} ? that ? Exactly... that would get you the name of the first player in the controlled by list... so as an example, that would resolve down to: !token-mod --set controlledby|timmaugh ...by the time Token-Mod saw the command line. This is a way to transfer 1 control to 1 player, which is what I think you want. On the other hand, if there is more than one player in the controlledby list and what you wanted was to duplicate that full list... there is no way to do that (currently), until either Aaron gets it added to TokenMod or I write that plug-in to plugger. Which I'm going to write right now. I've been needing a text replacement metascript for a couple of solutions, now. =D Actually that doesn't work. It doesn't write  the name of the targetted player  in the controlledby field of the selected token
1673133947
timmaugh
Pro
API Scripter
OK, so I'm working on this in my test game, too... and I don't have it completely working, but I think I have the metascript portion correct. First, the example you supplied to which I said, "Exactly" actually had a curly brace at the end of the Fetch construction rather than a closing parentheses. It should have been: !token-mod --set controlledby|= @(@{target|token_id}.player_name) ...unless you might assign to a player with a space in their name, in which case you'll want apostrophes: !token-mod --set controlledby|=' @(@{target|token_id}.player_name)' Also, since you're using a targeting statement, you won't have a selected token when Token-Mod sees the message, so you'll need to supply something to the --ids argument (or use SelectManager to virtually select a token). If you intend to select the token of-which-you-wish-to-pass-control, then click on another target to supply the player to whom to assign control, then you can do: !token-mod --set controlledby|=' @(@{target|token_id}.player_name)' --ids @{selected|token_id} But, of course, you can supply that id in a number of different ways. I can get the above working in my game, except that I am running into trouble with Token-Mod and players with spaces in their names... though that could easily be (and most likely is) a lack of understanding of some nuance of Token-Mod on my part. I'm reaching out separately to get some clarity on that question, but if you don't have players with spaces in their names, the above should work just fine for you, so I thought I'd share it.
Perfect that works as I expected. Thanks for your help.  For the name with space, I think you need double quotes and not simple quotes (untested but read that upper in this post