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

msg.selected and @{target|token_id} (revisited again)

1467742564
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Is there any way to specify a target without clearing all the selected tokens? Can there be? Is this something that a feature request could improve, or is it impossible?&nbsp;Is it possible that the selected tokens could be evaluated before the target is selected so that both could be reported in the same message? I know that people have asked about this several times over the years, ( <a href="https://app.roll20.net/forum/post/890292/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/890292/slug%7D</a> ) Is there now a better work around than what is discussed in the two year old thread above where you add an extra step to the attack where you set a target? &nbsp;&nbsp;IE: you add a step where you ask which token(s) will be attacking, Then you press a different button to specify the target, etc. I don't want to add an extra step, because 90% of the actions are single PCs doing one thing with only one token. I hate to make things harder for the players than it absolutely has to be, and adding an acting token select step seems extremely suboptimal.&nbsp; This is getting to be a big issue for me, because I have been working to magnify the importance of tokens as opposed to character sheets. IE: I am storing status information in the tokens (as status markers). Status markers can provide bonus, penalties, armor, defenses, etc.&nbsp; I have the code setup to where actions act on all selected tokens, and if there are no selected tokens, it applies the command to all tokens of that character on the page. This works great for PCs where there are almost always only one token per page. And it works great for mooks when there are no targets specified. I can select two or three Mooks, and run a macro, and it will run that macro for each of them.&nbsp; The problem is when there are mooks with targets. My selection gets cleared, so my code applies it to all of that characters mooks on the page. This is not a huge problem if there are only a few mooks for that character. I can just ignore (for example) all but the last two results. The huge problem is when there are huge masses of mooks!&nbsp; So are there any suggestions for how best to handle this. &nbsp;Is this something that could be improeved with a feature request or is it baked into the way the system works?
1467825177
Lithl
Pro
Sheet Author
API Scripter
I mean, you could use @{target} for everything, but I don't think there's a one-step solution for your problem that utilizes both msg.selected and @{target}. I suppose you could also just let the players select any token on the board, if you trust them enough. =P
1467834195

Edited 1467834405
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am not sure what you mean by using @{target} for everything.&nbsp; I am using @{target} when when I have a target. The idea is that the selected tokens will attack the targeted token. The problem is that when I have a targeted token, I don't have any selected tokens, since targetting caused the selected tokens to clear. So I am not sure what you are suggesting.&nbsp; Let me go into a bit more detail as to what I am doing. I have a repeating section for skills. The repeating section has several items including name, rank, controling attribute, etc. One of the items is a selection menu like this. &lt;select name="attr_T_Target" style="width:6em;" title="@{repeating_talents_X_T_Target} &nbsp;What does this talent target."&gt; &nbsp; &nbsp; &lt;option value="None" selected &nbsp; &nbsp;title="This Talent does not target a defense."&gt;None&lt;/option&gt; &nbsp; &nbsp; &lt;option value="Ask: ?{Target Number|0}" title="Ask for target number when roll is made." &gt;Ask&lt;/option&gt; &nbsp; &nbsp; &lt;option value="@{target|PD}" title="This Talent targets Physical Defense." &gt;PD&lt;/option&gt; &nbsp; &nbsp; &lt;option value="@{target|MD}" title="This Talent targets Mystic Defense."&gt;MD&lt;/option&gt; &nbsp; &nbsp; &lt;option value="@{target|SD}}" title="This Talent targets Social Defense."&gt;SD&lt;/option&gt; This attribute gets passed by the Roll Button to the API as part of a chat command line !edParse (other stuff) Target: @{T_Target} So if the chat parser sees Target: None it does not do anything about that part of the command, and the API does it's thing with the rest of the command.&nbsp; If the chat parser see's Target: Ask:&nbsp;?{Target Number|0} &nbsp; &nbsp;It is going to automagically put the query box up and ask the user what target number he wants to use. The API uses this number as the target for actions by all the selected tokens.&nbsp; If the chat parser see's one of the lower three, it will (clear all the selected tokens) and fetch the appropriate defense number of the targetted token. Then in theory the selected tokens can know the target number they have to reach when they perform thier attacks, but the problem is that THERE ARE NO SELECTED TOKENs to attack, because the act of getting a target cleared them all.&nbsp; So once again, everything works fine and dandy if I am not selecting a target token. The problem is that whenever I have a skill setup to select a target token, the chat message never reports any selected tokens.&nbsp;
1467836833
Lithl
Pro
Sheet Author
API Scripter
Chris D. said: I am not sure what you mean by using @{target} for everything.&nbsp; I am using @{target} when when I have a target. The idea is that the selected tokens will attack the targeted token. The problem is that when I have a targeted token, I don't have any selected tokens, since targetting caused the selected tokens to clear. So I am not sure what you are suggesting.&nbsp; I mean replace checking the msg.selected array with using multiple @{target}s in the command: both for what you're currently using as targets, and for what you're currently selecting.
1467838047
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You could also probably change your API so that triggering it with tokens selected causes an API button to be output to the chat. Set that button up so that it incorporates the ID's of the selected tokens and clicking it brings up the target dialogs. The API's final effect is triggered once the API Command Buttons is clicked and all targets are selected.
1467866918
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Brian said: I mean replace checking the msg.selected array with using multiple @{target}s in the command: both for what you're currently using as targets, and for what you're currently selecting. But how does that work with a variable number of "actors".. I mean 50% of the time it is one token doing something that has no target.In that specific case I would want one target to specify the actor. 45% of the time it is one token doing something that has one target.In that specific case I would want two targets, one for the actor, and one for the target. So anything I do needs to be painless in those two cases. Then maybe 10% of the time, it is more than one token (usually 2 or 3, but maybe as many as 10) doing something to one token. So setting things up so that by default there are 10 actors is really the worst case scenario for the most common thing. It is probably better to just limit each action to one actor and repeat the action once for each actor.&nbsp; I have been trying to think of an approach like Scott C suggested, and will probably do something like that if I can find a way that is not to odious.&nbsp;
1467900632

Edited 1467901163
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Brian said: But how does that work with a variable number of "actors".. I mean 50% of the time it is one token doing something that has no target.In that specific case I would want one target to specify the actor. 45% of the time it is one token doing something that has one target.In that specific case I would want two targets, one for the actor, and one for the target. So anything I do needs to be painless in those two cases. Then maybe 10% of the time, it is more than one token (usually 2 or 3, but maybe as many as 10) doing something to one token. So setting things up so that by default there are 10 actors is really the worst case scenario for the most common thing. It is probably better to just limit each action to one actor and repeat the action once for each actor.&nbsp; I could see setting up the script so that you have a command syntax like this: !API 4actors [Script would then expect 4 target values here] 5targets [script would expect 5 target values here]. You could probably make it dynamic by splitting the actors and targets argument (4actors and 5targets in this case) so that the script can see the number and then just calculate how many targets it needs for each one, rather than having to program a huge number of if statements for all your expected numbers of actors and targets. EDIT: You could actually probably use roll tags for this and then the API would read it as an inline roll. Something like: !API [[5[actors]]]. I haven't checked, but the [actors] part of the inline roll should be in the args &nbsp;expr&nbsp;part of the msg.content, so you could parse it out relatively easily. I have been trying to think of an approach like Scott C suggested, and will probably do something like that if I can find a way that is not to odious.&nbsp; I'd suggest doing a command syntax like: !API action [# of targets]--- This command would grab whatever the currently selected tokens are and use them as the actors. It would collect all of the actors like so: var actors ='|'; _.each(tokenid,function(id){ actors+=id+'|'; }; Your API button would then be the following syntax: !API act actors [A variable number of @{target|token_id} calls based on the # of targets passed in the inital API command] -Scott EDIT: adding code segments broke the quote formatting, have fixed.
1468446029
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Just for the edification of anybody looking to solve this same problem in the future, I am going to give here a detailed list of how I think my Earthdawn sheet is going to end up solving this problem. I went down several blind ally's that the reader can avoid. I have Talents and Skills in separate repeating sections. They have several options, among them is Target. Target is a drop down select statement that includes the following.&nbsp; &nbsp; &lt;option value="None" selected &nbsp; &nbsp;title="This skill does not target a defense."&gt;None&lt;/option&gt; &nbsp; &lt;option value="Ask: ?{Target Number|0}" title="Ask for target number when roll is made." &gt;Ask&lt;/option&gt; &nbsp; &lt;option value="PD" title="This skill targets Physical Defense." &gt;PD&lt;/option&gt; &nbsp; &lt;option value="MD" title="This skill targets Mystic Defense."&gt;MD&lt;/option&gt; &nbsp; &lt;option value="SD" title="This skill targets Social Defense."&gt;SD&lt;/option&gt; Each row also has a RowID where I store the ID of that repeating section entry (since for some reason that is not available otherwise). Calls to my API are of the following form. &nbsp; value="!edParse~ charID: @{character_id} ~ Target: @{SK_Target} ~ foreach ~ Action: SK: @{SK_RowID}: ?{Modification|0}" Target is passed as a parameter, since if the value is "Ask" having it as a parameter cause it to automatically have a popup appear and ask the user. A popup also always appears asking if there is a modification to this roll.&nbsp; If the target is PD, MD, or SD, then the API has been hard-coded to look at what tokens are selected, and send&nbsp; "[Click Here to Select Target](!edParse~ TokenList: (token IDs of selected tokens)~ TargetID: &nbsp;&#" + "64;{target|token_id}~ Action: SK: (RowID): 0)" Which will cause a button to appear in the chat window. When the user pushes it, it will ask for the Target ID. Note that the UF8 code for @ needs to be split up into two separate strings or the ADI will interpret it to soon.&nbsp; When the Action command is reached, the API looks up all the values needed for that dice roll (including the target number - using the targets ID) and makes the roll.&nbsp; Which is to say if the Target is None or Ask, then after the modifications have been entered, the system will simply make the requested dice rolls for each selected token.&nbsp; If the Target is PD, MD, or SD, it will put a button in the chat window, asking to be pressed, and when pressed it ask for a target token and then will make the requested dice roll for each previously selected token.&nbsp; When the results are in, the system compares the results to the target number and announces a success or failure.&nbsp; It also stores the target (in the status marker field of the token) for a short time, and &nbsp;if the very next roll for that token is a damage roll, the damage is automatically applied to that same target. I have also got it set so that any token that "missed" it's last attack roll does not bother to roll damage.&nbsp; this way you can select a group of tokens that are all firing at target #1, Tell them to roll. You will see the results (such as that 2 hit, and 3 missed), then select the same 5 tokens, roll damage and it will only roll damage for the 2 targets that hit.&nbsp; So I think this is the best that can be done with the limitations of what the system will allow..&nbsp;However i don't think the solution is very good. I simply think the limitations don't allow anything better. I continue to believe that as a minimum the VTT should be reprogrammed so that it figures out what tokens are selected before it clears it for the selections for target selection. This is basically what I have been trying to recreate, but my recreation involves making the user push an extra button.&nbsp; A better solution would be it records what tokens are selected before it clears them for target selection, and then after target selection it immediately and automatically reselects the previously selected tokens. If there is any way for me to code that I would appreciate if somebody could clue me in. &nbsp; A tertiary solution would be that there was some way for the API to tell the browser to run the code to have it select a target, without requiring the user to push a button. I think it is fairly basic UID that any mandatory step ought to be automated. Every time that button appears, the user is to press it. The user should not be required to press a button, the button should not even appear, That process should be automated. I am unawair of any way to automate it.&nbsp;