Macros as subroutines

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
Megoru
Kobold
Posts: 2
Joined: Sat Dec 06, 2008 4:11 am

Macros as subroutines

Post by Megoru »

I know this is written somewhere in the forums but after a couple of hours spent looking for this and that on random forum pages I'm a bit confused...

I can find documentation about the macrolink function but not directly regarding simple macro function.

How do I exactly use macros like subrountines inside other macros?
- How to pass arguments (I know "arg=value;arg=value;ecc..." but where do I put it in the macro call?
- How to retrieve the return value?

thanks for your help.

p.s. Is there a "complete" list of "all" the function? You know, just having an alphabetically rodered list of function signatures would help a lot...
MapTool is fantastic by the way ;)

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Macros as subroutines

Post by Rumble »

Megoru wrote:I know this is written somewhere in the forums but after a couple of hours spent looking for this and that on random forum pages I'm a bit confused...

I can find documentation about the macrolink function but not directly regarding simple macro function.

How do I exactly use macros like subrountines inside other macros?
- How to pass arguments (I know "arg=value;arg=value;ecc..." but where do I put it in the macro call?
- How to retrieve the return value?

thanks for your help.

p.s. Is there a "complete" list of "all" the function? You know, just having an alphabetically rodered list of function signatures would help a lot...
MapTool is fantastic by the way ;)
If you access this document:

http://docs.google.com/Edit?tab=view&do ... _3c9kmm4cq

and go to Branching Options in the contents, you'll find an explanation there.

Basically, you call a macro using the format described (the called macro can only reside on the Lib:token), and it can have 1 argument (which can be a property string, like "attack=9; damage=10; critical=11;").

The receiving macro receives that argument as the variable macro.args, and can optionally assign a value to the variable macro.return, which is passed back to the calling macro.

User avatar
Saagael
Giant
Posts: 174
Joined: Fri Aug 01, 2008 11:38 pm
Location: Orange County

Post by Saagael »

I have a similar question.

I am using a property string to send multiple arguments to a macro that determines if you hit or not. I need to send 1) a list of targets 2) the attack result, and 3) the defense used. This is the code I have so far:

Code: Select all

[H: attackProps = "targetList = nameList ; attRoll = AttackResult ; defense = Defense"]
[MACRO("Process Attack@Lib:Common"): "attackProps"]
The MACRO function works correctly, and it calls the macro, in which I have the code:

Code: Select all

[H: attack = getStrProp(macro.args, "attRoll")]
[H: defense = getStrProp(macro.args, "defense")]
[H: targList = getStrProp(macro.args, "targetList")]

[H:ValTargs=listCount(targList)]

[COUNT(ValTargs, "<br>"), CODE:
  {
    [H: CurrentEnemy=listGet(targList,roll.count)]
    [H,token(CurrentEnemy): targetDef=getProperty(defense)]
    [IF(attack >= targetDef, "You hit " +CurrentEnemy+ ".", "You missed " +CurrentEnemy+ ".")]
  }] 
And that SHOULD change all the properties in attackProps to variables used by the macro.

The problem I have is that the the list of targets doesn't seem to be holding a list anymore, because no matter what I do, the loop never initiates. I don't know if string properties convert all lists and numbers to static strings of text, in which case, is there a workaround? I'm so close to having a workable "select and attack" system that I'd like to get this worked out.

EDIT: I should probably put this in the MapTools forum...

Megoru
Kobold
Posts: 2
Joined: Sat Dec 06, 2008 4:11 am

Post by Megoru »

Thank you very much Rumble! :D

User avatar
Daniel
Giant
Posts: 132
Joined: Thu Nov 20, 2008 3:49 am
Location: Germany (GMT +1)

Post by Daniel »

Saagael, remove the [H: ]'s in the first lines of your macro where you read in the parameters. This will probably show you exactly what's going wrong.

I also had issues with apparently trivial parameter passing, and it took me hours to realize it was just because I had used the wrong delimiters for lists/parameter strings or stuff like that. The impression I got was there are different requirements when you're passing only strings, only numbers or a mix in a propString. Try for example adding a final ; in your parameterString, but really most importantly remove the H: 's and see what it is that you are passing, or rather what is read out from it, like so:

Code: Select all

all arguments: [macro.args] <br>
attack: [attack = getStrProp(macro.args, "attRoll")] <br>
def: [defense = getStrProp(macro.args, "defense")]<br>
targList: [targList = getStrProp(macro.args, "targetList")] <br>

Post Reply

Return to “Documentation Requests/Discussion”