Any way to get all token identifiers including lib: tokens?

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
User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Any way to get all token identifiers including lib: tokens?

Post by bubblobill »

I have recently taken up the practice of putting useful information in the Tool-tip property for my macros. Pretty crazy I know. Particularly useful as a reference for help text such as the type and order of function parameters.

I then took it a step further and created a "help" UDF which I use in the chat window.
Like this:

:arrow: [help("help")]
:arrow: Help for "help": Returns the tooltip text for a macro. Usage [help("macro name")]
:arrow: [help("openDialog")]
:arrow: Help for "openDialog": openDialog arguments: Name, Width, Height, Input, Temporary, Title, NoFrame, Content

It searches for macros on its home library token first, then looks at other tokens if it cannot find it. My problem is that most useful things such as UDFs will be stored on a library token, and the getTokens and getTokenNames functions do not return library token IDs. Am I missing something or is there no way to obtain the library tokens identifiers?
Here is the code for those that are interested.

Code: Select all

<!-- return tooltip text for macro -->
[h: tokName="lib:Input"]
[h: switchToken(tokName)]

<!-- create thyself -->
[h, if(!isFunctionDefined("help")):defineFunction("help", "help@"+tokName)]
<!-- bug out if no arguments provided -->
[s, h: assert(if(arg(0)=="",0,1), "Help: No function name provided", 0)]

<!-- get the tooltip text from macro on this token -->
[h: macroName=arg(0)]
[h: macroIndex=getMacroIndexes(macroName)]

<!-- if found do one thing, if not, do the other thing -->
[s, if(isNumber(macroIndex)), code:{
	<!-- branch for macro found locally -->
	[h: tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
	[r, if(tipText==""): "Help for ""+macroName+"": No tip available."; "Help for ""+macroName+"": "+tipText]
	};{
	<!-- branch for macro external search -->
	[h: allTokens=getTokens("json")]
	[h: numTokens=json.length(allTokens)]
	[h:tok=0][h: helpString=""][h:tipText=""]
	<!-- loop through tokens until macro found -->
	[h, while(tok < numTokens), code:{
		[h: switchToken(json.get(allTokens, tok))]
		[h: tok=tok+1]
		[h: macroIndex=getMacroIndexes(macroName)]
		[h, if(isNumber(macroIndex)): tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
		[h, if(tipText=="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": No tip available."]
		[h, if(tipText!="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": "+tipText]
		[h, if(helpString!=""):tok=numTokens]
	}]
	<!-- spit out the results -->
	[r, if(helpString==""): "Help for ""+macroName+"": Macro was not found."; helpString]
}]
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

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

Re: Any way to get all token identifiers including lib: toke

Post by aliasmask »

Maybe Wiki: getVisible() will work.

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Any way to get all token identifiers including lib: toke

Post by bubblobill »

oorah Mr Mask.

You were wrong, but close.

http://www.lmwcs.com/rptools/wiki/getVisibleTokens did the trick.
Updated version with the trick

Code: Select all

<!-- return tooltip text for macro -->
[h: tokName="lib:Input"]
[h: switchToken(tokName)]

<!-- create thyself -->
[h, if(!isFunctionDefined("help")):defineFunction("help", "help@"+tokName)]
<!-- bug out if no arguments provided -->
[s, h: assert(if(arg(0)=="",0,1), "Help: No function name provided", 0)]

<!-- get the tooltip text from macro on this token -->
[h: macroName=arg(0)]
[h: macroIndex=getMacroIndexes(macroName)]

<!-- if found do one thing, if not, do the other thing -->
[s, if(isNumber(macroIndex)), code:{
   <!-- branch for macro found locally -->
   [h: tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
   [r, if(tipText==""): "Help for ""+macroName+"": No tip available."; "Help for ""+macroName+"": "+tipText]
   };{
   <!-- branch for macro external search -->
   [h: allTokens=json.union(getTokens("json"), getVisibleTokens("json"))]
   [h: numTokens=json.length(allTokens)]
   [h:tok=0][h: helpString=""][h:tipText=""]
   <!-- loop through tokens until macro found -->
   [h, while(tok < numTokens), code:{
      [h: switchToken(json.get(allTokens, tok))]
      [h: tok=tok+1]
      [h: macroIndex=getMacroIndexes(macroName)]
      [h, if(isNumber(macroIndex)): tipText=json.get(getMacroProps(macroIndex, "json"), "tooltip")]
      [h, if(tipText=="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": No tip available."]
      [h, if(tipText!="" && isNumber(macroIndex)): helpString="Help for ""+macroName+"": "+tipText]
      [h, if(helpString!=""):tok=numTokens]
   }]
   <!-- spit out the results -->
   [r, if(helpString==""): "Help for ""+macroName+"": Macro was not found."; helpString]
}]
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

Post Reply

Return to “Macros”