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?
Input ( LIST)
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: Input ( LIST)
You were close. There are a couple of ways to do it, but strformat is what I prefer to do:
This may be too complicated for you, but this is a function I use.
Code: Select all
[h: tokenList=getVisibleTokenNames()]
[h: abort(input(strformat("selected|%{tokenList}|Target|LIST|Value=String")))]
[r: selected]
||| 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]
!!
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Input ( LIST)
Thanks this is exactly what I was looking for