Accessing global/campaign/other tokens' macros.

13 views
Skip to first unread message

Mora Fermi

unread,
Apr 23, 2014, 6:08:50 PM4/23/14
to t3-dis...@googlegroups.com
Hi,

Can you give a quick example on how to call other macros, especially campaign-wide and located in other tokens? I have quite a few macros planned with large amount of "overlap", so I would prefer to split common functions out for easier maintenance.

Thank you.

manuel...@googlemail.com

unread,
Apr 24, 2014, 12:24:47 PM4/24/14
to t3-dis...@googlegroups.com
Created a new tutorial for that. It's called 3 because, well... it's not that important a topic and how campaign macros work will probably change soon.

http://tabletoptool.com/documentation/macro-tutorials/tutorial-3---campaign-functions

Mora Fermi

unread,
Apr 24, 2014, 3:57:21 PM4/24/14
to t3-dis...@googlegroups.com
Just a quick question to the above: parameter passing conventions? Since macros are not "standard", fully specified, Groovy functions/objects, there doesn't seem to be any obvious way how to access any parameters. Reflection is not very useful inside macros, either. :-/

Thanks.

Virenerus

unread,
Apr 28, 2014, 2:12:45 AM4/28/14
to t3-dis...@googlegroups.com
You can simply pass a map to the execute method. In groovy this looks something like:

['id':'FX-11', 'name':'Radish', 'no':1234, 99:'Y']

you can then simply access this map via the variable args

Mora Fermi

unread,
Apr 28, 2014, 3:40:16 AM4/28/14
to t3-dis...@googlegroups.com
How to *return* a value? simple "return this" doesn't work.

Virenerus

unread,
Apr 28, 2014, 10:05:48 AM4/28/14
to t3-dis...@googlegroups.com
It does not? I tried it just now and it worked for me. Could you post the calling and called macro?

Just to be clear: The called macro can simply do something like:

return 5;


This will then become the returned value of the execute() call.

Mora Fermi

unread,
May 1, 2014, 6:35:52 AM5/1/14
to t3-dis...@googlegroups.com
Here are my macros:

Campaign macro, "hello":

output = "Hello "
args.each {output += it + " "}

return output

and the calling macro from a token:

print ("###########################\n")

out = campaign.getCampaignMacro("hello").execute([arg1: "Test", arg2: "Hello"])

print ("Out: $out")

When I click on the calling macro, I get this:

###########################
null


The "null" is printed in red, for some reason.

Mora Fermi

unread,
May 3, 2014, 5:19:38 AM5/3/14
to t3-dis...@googlegroups.com
This actually works for token macros:

macro "local_hello":

return "Hello from local_hello"

and "Testing calls", on the same token:

print (token.getMacro("local_hello").execute())

prints out what is expected.
Message has been deleted

Mora Fermi

unread,
May 5, 2014, 5:07:45 PM5/5/14
to t3-dis...@googlegroups.com
I've run into this lovely stack trace, I hope it helps:

2014-05-05 23:01:35,784 [model.MacroButtonProperties:337] ERROR - Error while trying to execute a macro from button
com.t3.macro.MacroException: Error while trying to run:Script1@464120bb
at com.t3.macro.groovy.GroovyMacroEngine.run(GroovyMacroEngine.java:59)
at com.t3.macro.groovy.GroovyMacroEngine.run(GroovyMacroEngine.java:1)
at com.t3.macro.MacroEngine.run(MacroEngine.java:62)
at com.t3.model.MacroButtonProperties.executeCommand(MacroButtonProperties.java:335)
at com.t3.model.MacroButtonProperties.executeCommand(MacroButtonProperties.java:300)
at com.t3.model.MacroButtonProperties.executeMacro(MacroButtonProperties.java:260)
at com.t3.client.ui.macrobuttons.buttons.MacroButton.mouseReleased(MacroButton.java:198)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.t3.client.swing.T3EventQueue.dispatchEvent(T3EventQueue.java:35)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: groovy.lang.MissingMethodException: No signature of method: com.t3.macro.api.functions.CampaignFunctions.getMacro() is applicable for argument types: (java.lang.String) values: [hello]
Possible solutions: iterator(), getAt(java.lang.String)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.run(Script1.groovy:3)
at com.t3.macro.groovy.GroovyMacroEngine.run(GroovyMacroEngine.java:57)
... 40 more


this is thrown when trying to run "campaign.getCampaignMacro("hello").execute()"

Mora Fermi

unread,
May 5, 2014, 5:12:20 PM5/5/14
to t3-dis...@googlegroups.com
Oops, excuse me, wrong stack trace!

2014-05-05 23:11:04,589 [model.MacroButtonProperties:337] ERROR - Error while trying to execute a macro from button
com.t3.macro.MacroException: Error while trying to run:Script1@3aef4e71
Caused by: java.lang.NullPointerException
at com.t3.macro.api.functions.CampaignFunctions.getCampaignMacro(CampaignFunctions.java:110)
at com.t3.macro.api.functions.CampaignFunctions$getCampaignMacro.call(Unknown Source)
Reply all
Reply to author
Forward
0 new messages