How to make a macro execute another macro?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
deama
Cave Troll
Posts: 28
Joined: Mon Aug 05, 2013 8:31 am

How to make a macro execute another macro?

Post by deama »

How can I make a macro execute another macro in the same group?

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

Re: How to make a macro execute another macro?

Post by aliasmask »

See [macro:]

Code: Select all

<!-- call another macro, no parameters -->
[macro("macroName@lib:token"): ""]

<!-- call another macro, give parameters -->
[macro("macroName@lib:token"): json.append("","arg1","arg2")]

<!-- get return value after calling macro -->
[H: returnVal = macro.return]
lib:token is the name of a token that has "lib:" in front of the name. For example, "lib:combat" would be a valid lib token name. Lib tokens hold a collection of macros that can be called by other macros but using it's name after the @ symbol. macroName is just the name you give the macro. For example, I may have "Attack" as a macro name on "lib:combat" and if want to call it I use "Attack@lib:combat".

deama
Cave Troll
Posts: 28
Joined: Mon Aug 05, 2013 8:31 am

Re: How to make a macro execute another macro?

Post by deama »

aliasmask wrote:See [macro:]

Code: Select all

<!-- call another macro, no parameters -->
[macro("macroName@lib:token"): ""]

<!-- call another macro, give parameters -->
[macro("macroName@lib:token"): json.append("","arg1","arg2")]

<!-- get return value after calling macro -->
[H: returnVal = macro.return]
lib:token is the name of a token that has "lib:" in front of the name. For example, "lib:combat" would be a valid lib token name. Lib tokens hold a collection of macros that can be called by other macros but using it's name after the @ symbol. macroName is just the name you give the macro. For example, I may have "Attack" as a macro name on "lib:combat" and if want to call it I use "Attack@lib:combat".
What if I want to call a none lib token? So say a PC token with the name "Uvogin"?

EDIT: Also, once the macro from my campaign tab calls a macro from a lib token, how do I make the "lib token called macro" apply it's affects to the selected token (which I selected before clicking the macron in my campaign tab)?

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

Re: How to make a macro execute another macro?

Post by bubblobill »

EDIT: I take it all back. Listen to him instead
Last edited by bubblobill on Tue Jul 29, 2014 7:07 am, edited 1 time in total.
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
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: How to make a macro execute another macro?

Post by wolph42 »

bubblobill wrote:Generally a macro will effect the selected token properties no matter where it is called from.
erm...no! Generally it won't

It will only effect selected token IF 'apply to selected tokens' is checked (but that won't work with [macro:]) or if the macro is run from the token.
In all other cases you need to do add the following inside your macro:

Code: Select all

[tok = getSelectedNames()]
[assert(listCount(tok)==1, "make sure only one token is selected",0)]
[switchToken(tok]

<!-- your macro here -->
 
EDIT: Also, once the macro from my campaign tab calls a macro from a lib token, how do I make the "lib token called macro" apply it's affects to the selected token (which I selected before clicking the macron in my campaign tab)?
By using the code above in the local macro.
...@Uvogin might work
that WON'T work (the error will tell you that only lib: tokens can be called macros from). The only way to get that working is having 'apply to selected token checked' on the campaign macro, campaign macro looks like this:

Code: Select all

[macro("test@TOKEN"):""]
where 'test' is the macro name on the Uvogin token.
Then select the Uvogin token and then run the macro. In this case the macro is run FROM uvogin so the 'getSelectedNames' code here above is NOT required.

deama
Cave Troll
Posts: 28
Joined: Mon Aug 05, 2013 8:31 am

Re: How to make a macro execute another macro?

Post by deama »

Thanks guys; though I got another question...

Ok; let's say I select a token, and I press a macro in the campaign tab which calls a macro in a lib token. Now; when this happens, the macro from the lib token asks me for the variable values, but how do I make it use the variable values from the selected token? Without using the "apply to selected tokens" option?

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

Re: How to make a macro execute another macro?

Post by aliasmask »

Use Wiki: getSelected() to get the id and then Wiki: switchToken() to set the current impersonated token.


Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: How to make a macro execute another macro?

Post by Kurghoth »

I have some problem with Macro arguments that i am not able to figure out...

I have a lib token named lib:AuraD

It own 3 macros
- RedTurn
- SelTarget
- CalDamage

On "Global" tab i have a macro that should call all of the macro from the lib:AuraD

Code: Select all

[macro("RedTurn@lib:AuraD"): ""]
[macro("SelTarget@lib:AuraD"): ""]
[macro("CalDamage@lib:AuraD"): ""]
Problem is that I get this error:

Statement options (if any): macro("RedTurn@lib:AuraD")
Statement Body : ""

if I try to change "" to something else i keep getting this error... I wonder when I will figure out how calling macro works on MapTool... I feel stupid...

:?

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: How to make a macro execute another macro?

Post by wolph42 »

I dont see anything wrong with what you provided, thus the problem lies elsewhere.
E.g. names the macro differently on the lib: or a syntax error in the macro, etc.

Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: How to make a macro execute another macro?

Post by Kurghoth »

I tried to change name of the macros to:

- Next
- Target
- Calcola

Macro on Global tab is:

Code: Select all

[macro("Next@lib:AuraD"): ""]
[macro("Target@lib:AuraD"): ""]
[macro("Calcola@lib:AuraD"): ""]
Spoiler
Macro "Next"

Code: Select all

[h: turnrim=getProperty("turni")]
[h: sott=1]
[h: calcolo=(turnrim-sott)]
[h: setProperty("turni",calcolo)]
Rimarrò attiva per altri [r: turni] turni
[h, if (calcolo>0), CODE: {
  [setVisible(1)]
  [setState("Hidden",0)]
};
{ [setVisible(0)]
  [setState("Hidden",1)]
}]
Macro "Target"

Code: Select all

[h: penetrazione=getProperty("PenSpi")]
[h: danni=getProperty("Dan")]


[H: "Tokens = "+ listCount(getTokens())]
[H: ts = json.get(getInfo("server"),"timeInMs")]
[H: x = getTokenX()]
[H: y = getTokenY()]
[H: range = 9]
[H: gridSize = json.get(json.get(getInfo("map"),"grid"),"size")]
[H: quad1 = getTokens("json",json.set("{}","selected",0,"range",json.set("{}","upto",range)))]
[H: moveToken(x-gridSize,y)]
[H: quad2 = getTokens("json",json.set("{}","selected",0,"range",json.set("{}","upto",range)))]
[H: moveToken(x-gridSize,y-gridSize)]
[H: quad3 = getTokens("json",json.set("{}","selected",0,"range",json.set("{}","upto",range)))]
[H: moveToken(x,y-gridSize)]
[H: quad4 = getTokens("json",json.set("{}","selected",0,"range",json.set("{}","upto",range)))]
[H: moveToken(x,y)]
[H: inArea = json.intersection(json.intersection(json.intersection(quad1,quad2),quad3),quad4)]
[H: onWall = "[]"]
[H, foreach(token,inArea), code: {
   [H, if(getDistance(token) == range): onWall = json.append(onWall,token)]
}]
[H: moveToken(x-gridSize,y)]
[H, foreach(token,inArea), code: {
   [H, if(getDistance(token) == range): onWall = json.append(onWall,token)]
}]
[H: moveToken(x-gridSize,y-gridSize)]
[H, foreach(token,inArea), code: {
   [H, if(getDistance(token) == range): onWall = json.append(onWall,token)]
}]
[H: moveToken(x,y-gridSize)]
[H, foreach(token,inArea), code: {
   [H, if(getDistance(token) == range): onWall = json.append(onWall,token)]
}]
[H: moveToken(x,y)]
[H: onWall = json.unique(onWall)]
[H: time = json.get(getInfo("server"),"timeInMs") -  ts]

[h: strformat("Range from token %s = %{range}",getName())]
[h: "Nell'area = "]
[h, foreach(token,inArea): getName(token)]

[h, foreach(token,inArea): selectTokens(token,1)]

[h, foreach(token,onWall): getName(token)]

[h: switchToken("AuraTemp")]

[h: setProperty("PenSpi", penetrazione)]
[h: setProperty("Dan", danni)]

[h: ids = getWithState("Amico")]
[h, foreach(id, ids), Code:{
    [deselectTokens(id)]
}]

[h: ids = getWithState("Morto")]
[h, foreach(id, ids), Code:{
    [deselectTokens(id)]
}]
Macro "Calcola"

Code: Select all

[h: switchToken("AuraTemp")]
[h:pen=getProperty("PenSpi")]
[h:danno=getProperty("Dan")]

[h: ids = getSelected()]
[h, foreach(id, ids, "<br>"),Code:{
[h: switchToken(id)]
[H: donkey=getProperty("AssFisFigura")]
[h, if(pen>=donkey), Code:{
    [h:PuntiSalute = PuntiSalute - danno]
    [h:bar.Health = PuntiSalute / MaxPS]
}]
[h, if(PuntiSalute <=Vit && PuntiSalute > 0): setState("Moribondo", 1); setState("Moribondo", 0)]
[h, if(PuntiSalute <=Vit && PuntiSalute > 0): text = "Atento!!! Sei in stato Moribondo. Da adesso in poi perderai 5 Punti salute alla fine di ogni tuo turno."; text=""]
[h, if(PuntiSalute <= 0): text = "Mi dispiace, sei morto!"]
[h, if(PuntiSalute <= 0): setState("Morto", 1); setState("Morto", 0)]
}]
Here is how it should work.

I have a token that represent an Area Spell that make Damage over time and lasts 10 round.
First macro should lower round count one by one.
Second one should select all the token in the Area of Effect and then deselect the friendly target.
Third one should compere atk stats with defensive stats and, if atk is successful, calculate damage.

I hope everything is clear. English is not my first language and sometimes it's hard to explain things :P

Obviously I keep getting the error

Edit: I tried to copy macros on the global panel to launch them directly one by one... if i do it this way everything work fine... it stop working only if i try to start them from the Lib:Token.

Last Edit... I tried to change Lib:token name... and now seems to work... As long as I would like to learn... is there a reason for this? so i can avoid to make the same error next time...

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: How to make a macro execute another macro?

Post by wolph42 »

what was the name of the lib token and to what name did you change it?

i also noticed : [h: turnrim=getProperty("turni")] without any context (e.g. switchtoken() or adding the id of the token where youre getting the property ffrom. That also might cause an issue.

Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: How to make a macro execute another macro?

Post by Kurghoth »

The name was Lib:AuraD and I changed to lib:aura
i also noticed : [h: turnrim=getProperty("turni")] without any context (e.g. switchtoken() or adding the id of the token where youre getting the property ffrom. That also might cause an issue.
I see... actually that macro have "Apply to selected token" on... it take Property from the selected token.

Ok... now i am confused... I had changed nothing more... it was working... it doesn't work anymore...

:shock: :?


Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: How to make a macro execute another macro?

Post by Kurghoth »

Do you want me to translate it so it comes in english? it's in Italian At the moment...

The file is almost 40MB... can i link it from dropbox or google drive?

Post Reply

Return to “MapTool”