RPTools.net

Discussion and Support

Skip to content

It is currently Wed Dec 13, 2017 9:13 pm 






Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Cave Troll
 
Joined: Sun Jan 24, 2010 3:07 pm
Posts: 45
 Post subject: Any way to get all token identifiers including lib: tokens?
PostPosted: Wed Nov 22, 2017 3:50 am 
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?

Code:
<!-- 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 &quot;"+macroName+"&quot;: No tip available."; "Help for &quot;"+macroName+"&quot;: "+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 &quot;"+macroName+"&quot;: No tip available."]
      [h, if(tipText!="" && isNumber(macroIndex)): helpString="Help for &quot;"+macroName+"&quot;: "+tipText]
      [h, if(helpString!=""):tok=numTokens]
   }]
   <!-- spit out the results -->
   [r, if(helpString==""): "Help for &quot;"+macroName+"&quot;: Macro was not found."; helpString]
}]


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7967
Location: Bay Area
 Post subject: Re: Any way to get all token identifiers including lib: toke
PostPosted: Wed Nov 22, 2017 5:00 am 
Maybe Wiki: getVisible() will work.

_________________
Downloads:


Top
 Profile  
 
 Offline
Cave Troll
 
Joined: Sun Jan 24, 2010 3:07 pm
Posts: 45
 Post subject: Re: Any way to get all token identifiers including lib: toke
PostPosted: Thu Nov 23, 2017 3:09 am 
oorah Mr Mask.

You were wrong, but close.

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

Code:
<!-- 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 &quot;"+macroName+"&quot;: No tip available."; "Help for &quot;"+macroName+"&quot;: "+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 &quot;"+macroName+"&quot;: No tip available."]
      [h, if(tipText!="" && isNumber(macroIndex)): helpString="Help for &quot;"+macroName+"&quot;: "+tipText]
      [h, if(helpString!=""):tok=numTokens]
   }]
   <!-- spit out the results -->
   [r, if(helpString==""): "Help for &quot;"+macroName+"&quot;: Macro was not found."; helpString]
}]


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 3 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman