Input ( LIST)

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
talmaru
Kobold
Posts: 13
Joined: Fri Oct 10, 2014 7:19 am

Input ( LIST)

Post by talmaru »

I am trying to create a macro that will get all visible names and then ask the player to select one from a drop down list

[h: tokenList=getVisibleTokenNames()]
[h: input("Selected|tokenList|Target|LIST|Value=String")]
[selected]

Is what I tried.
This will only put the word tokenList into the list.
How do I get maptools to parse tokenList as a string populate the list?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Input ( LIST)

Post by aliasmask »

You were close. There are a couple of ways to do it, but strformat is what I prefer to do:

Code: Select all

[h: tokenList=getVisibleTokenNames()]
[h: abort(input(strformat("selected|%{tokenList}|Target|LIST|Value=String")))]
[r: selected]
This may be too complicated for you, but this is a function I use.
||| getSeenTokens |||

Code: Select all

@@ @getSeenTokens
<!-- getSeenTokens(options): json array or object 

options (strprop or json object)
   PC - 0 any token, 1 - PC only
   NPC - 0 any token, 1 - NPC only
   Range - upto this distance in grid units (ie feet, and not grid squares); 0 - any range
   Self - 0 do not include self, 1 include self
   Names - 0 ids only (json array), 1 ids and names (json object)
   
This function will get a list of tokenIds based on the current tokens vision type. hasSight is always turned on for source. If NPC is source, 
   then this may have erroneous results if the sight type is incorrect.
-->

[H: options = lower(arg(0))]
[H: sourceToken = currentToken()]

[H: assert(! json.isEmpty(sourceToken),"<b>getSeenTokens(options):</b Current Token is not set.",0)]

<!-- define options locally -->
[H: defaults = json.set("{}","pc",0,"npc",0,"range",0,"self",0,"names",0)]
[H, if(json.type(options) == "UNKNOWN" && ! json.isEmpty(options)): options = json.fromStrProp(options)]
[H, if(json.isEmpty(options)): options = defaults; options = json.merge(defaults,options)]
[H: varsFromStrProp(json.toStrProp(options))]

<!-- get token ids -->
[H: conditions = "{}"]
[H, if(npc && ! pc): conditions = json.set(conditions,"npc",npc)]
[H, if(! npc && pc): conditions = json.set(conditions,"pc",pc)]
[H, if(range): conditions = json.set(conditions,"range",json.set("{}","token",sourceToken,"upto",range,"distancePerCell",1))]
[H: tokenIds = getTokens("json",conditions)]

<!-- include self if set -->
[H, if(! json.isEmpty(tokenIds)): tokenIds = json.difference(tokenIds,json.append("",sourceToken))]
[H, if(self), code: {
   [H, if(names): targets = json.set("{}",sourceToken,getName(sourceToken)); targets = json.append("",sourcetoken)]
};{
   [H, if(names): targets = "{}"; targets = "[]"]
}]

<!-- check each id for name and if seen -->
[H, if(! hasSight()): setHasSight(1)]
[H, foreach(tokenId,tokenIds), code: {
   [H: canSee = ! json.isEmpty(canSeeToken(tokenId))]
   [H, if(canSee), code: {
      [H, if(names): targets = json.set(targets,tokenId,getName(tokenId)); targets = json.append(targets,tokenId)]
   };{}]     
}]

[H: macro.return = targets]

!!
 

talmaru
Kobold
Posts: 13
Joined: Fri Oct 10, 2014 7:19 am

Re: Input ( LIST)

Post by talmaru »

Thanks this is exactly what I was looking for

Post Reply

Return to “Macros”