RPTools.net

Discussion and Support

Skip to content

It is currently Thu Feb 22, 2018 11:55 pm 






Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8012
Location: Bay Area
 Post subject: putMacro() - variant of createMacro()
PostPosted: Thu Jan 21, 2010 6:53 am 
If you want to create a macro on a target token, but want to keep the process separate from any other functionality you're running. Here is a bit of code I wrote. It requires two parts, my macro "putMacro" and the macro that calls putMacro with the relevant data. putMacro will sort out the targets selected, check for duplicates and you can even put in your own custom condition that is checked on the selected tokens.

To use. select the library token with putMacro and the creeation macro, hold down the shift key and select the other tokens to put the created macro on. Click the creation macro that calls putMacro and voila, new macros created on all the other tokens with no duplication.

Code:
<!-- This should be run on a lib token --->
[
h: assert(isTrusted() && !json.isEmpty(macro.args),"<b>putMacro(macroName,macroText,macroProps,delim,condition)</b>",0)]

<!--
 Verify all the arguments -->
[
h: tNumArgs = json.length(macro.args)]
[
h: assert(tNumArgs >= 3,"<b>putMacro(macroName,macroText,macroProps,delim,condition)</b>",0)]
[
h: tMacroName = json.get(macro.args,0)]
[
h: tMacroText = json.get(macro.args,1)]
[
h: tMacroProps = json.get(macro.args,2)]
[
h, if(tNumArgs >= 4), code:{
   [h: tType = json.get(macro.args,3)]
   [h: tType = if(tType != "",tType,";")]
};{
   [h: tType = ";"]
}]
[
h, if(tNumArgs >= 5), code:{
   [h: tCondition = json.get(macro.args,4)]
};{
   [h: tCondition = 1]
}]

<!--
 Get all the selected Tokens. Remove the one running the macro -->
[
h: tSelected = getSelected()]
[
h: mIds = listDelete(tSelected,listFind(tSelected,currentToken()))]

<!--
 Remove ids that already have the macro -->
[
h: tIds = mIds]
[
h, foreach(tId,mIds), code: {
   [h: tFound = listFind(getMacros(",",tId),tMacroName)]
   [h, if(tFound != -1), code: {
      [h: tIds = listDelete(tIds,listFind(tIds,tId))]
   };{}]
}]
   

<!-- Put the macro on the remaining tokens -->
[
h, foreach(tId,tIds), code: {
   [h: switchToken(tId)]
   [h: cCondition = eval("tCondition")]
   [h, if(cCondition), code: {
      [h: createMacro(tMacroName,tMacroText,tMacroProps,tType)]
   };{}]
}]
 


Example Caller:
Code:
 [h: putMacro("Spec Abils", "/self [macro('Spec Abil Main@Lib:spells'):'']","autoExecute=true;color=red;fontColor=yellow;group=Spells;sortBy=51",";")] 


In the above case, I made putMacro a User Defined Function in onCampaignLoad

This is more for the people writing code for others to use to make life simpler for those non-programmers out there.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9482
Location: Netherlands
 Post subject: Re: putMacro() - variant of createMacro()
PostPosted: Fri Jan 22, 2010 5:21 pm 
thnx!

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Site Admin
 
Joined: Mon Jun 12, 2006 12:20 pm
Posts: 12111
Location: Tampa, FL
 Post subject: Re: putMacro() - variant of createMacro()
PostPosted: Fri Jan 22, 2010 8:44 pm 
(Moved to the Drop-In Resources forum under User Creations, but I left a shadow thread in the MapTool > Macros forum.)


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