Multiple Selection

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
koorimusha
Kobold
Posts: 9
Joined: Wed Jun 17, 2015 3:56 pm

Multiple Selection

Post by koorimusha »

Currently in maptools, I am attempting to create some sort of code that will execute a command for multiple selected tokens without errors. Let me explain further:

For example, damage is calculated by Attack minus Defense. To do this, I normally use getImpersonated() and getSelected() to switch between tokens with switchToken() and that works. The idea is to find my Attack value by using getImpersonated() and then getting the selected's Defense value by using getSelected() and swapping between the two tokens by using switchToken(). But here's the problem. What if I wanted to come up with an attack that does AOE damage, i.e. harming multiple targets within one turn? If I highlight multiple tokens, it gives an error. Here's an example of what kind of code is being used:

Code: Select all

[h:enemy=getSelected()]
[h:player=getImpersonated()]

[h:switchToken(player)]
[h:attack=Strength]

[h:switchToken(enemy)]
[h:defense=AC]

[h:damage=1d20+attack-defense]
How would I be able to decrease the HP value of multiple targets within one turn without getting any errors and retaining the correct damage values for each enemy's unique stats? Hopefully, I am clear with my questions. If anymore information is needed, I will gladly reply with the required information.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Multiple Selection

Post by wolph42 »

well, since 'enemy' is now something like "Elf, Ork, Bad Guy, Good Guy, Dead Guy" you can expect it to fail when you use swithToken(enemy) because that 'token' does not exist.

Hence use

Code: Select all

[enemies=getSelectedNames()]
[foreach(enemy, enemies),CODE:{
  [switchToken(enemy)]
  [h:defense=AC]
  etc.
}]

koorimusha
Kobold
Posts: 9
Joined: Wed Jun 17, 2015 3:56 pm

Re: Multiple Selection

Post by koorimusha »

Thanks a lot for the advice! I learned something new and now I can progress a little. However, I did forget to mention another question I had about selecting multiple tokens. If I wanted to put a limit on how many tokens can be selected at once for a macro, how would I go about doing this? For example, a certain attack is only capable of attacking two targets, no more, no less, would there be a way to gather the value of how many tokens on the map was selected? Preferably, something that's assert() friendly to prevent the macro from being fully executed. Thanks again.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Multiple Selection

Post by aliasmask »

When you use getSelected it can return a list or a json. You can then use the list or json function to count the number selected.

Post Reply

Return to “MapTool”