TOKEN macro and sub-macros

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
Blakey
Dragon
Posts: 778
Joined: Fri Mar 23, 2007 11:27 am
Location: Sussex, UK.

TOKEN macro and sub-macros

Post by Blakey »

I have a macro on a floating HTML frame that knows which token the frame belongs to - because I set up the token name as a argument to the macro itself. I want to use this macro to call library macros with the token as the 'current token'. I'm using Token() roll option to do this and have also tried switchToken() macro. Both these work fine for the initial macro I call from the HTML frame. However if this maco calls a sub-macro then the token() macro appears to have gone out of scope and you get all sorts of errors. Hopefully this explanation makes sense.

So, the question is, inside a macro on a FRAME, how do I set up "current token" and leave it valid for sub-macros? Am I asking too much?

Is the only way to do this to pass the token name along to the submacros and have them all use Token() roll macro as well?

Cheers!
Blakey
The guy in the green hat.

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

Re: TOKEN macro and sub-macros

Post by wolph42 »

this might be a bit cumbersome and maybe there is an easy solution to your problem.
If there isn't, what you could try to do is create a json property on a lib e.g. ident2token, where you store {identifier:currentToken}
The identifier must be unique for the floating frame and can be passed onto macros. These macros can get the currentToken id from the lib using the unique identifier.
I hope this makes sense and is of any use.

Thinking of this, passing the id of a token as an argument should be exactly the same, so if that doesnt work, likely this doesnt either...

ah maybe it can be done much easier, but Im not certain how you've build it. Basically the above is: create a chache and retrieve data when needed.
And as you will never be running two macros at the same time you can also just store the id of the current toke in a lib property and retrieve it when needed. Thats way easier AND you don't need to pass on any arguments.

cheerz mate!

User avatar
Blakey
Dragon
Posts: 778
Joined: Fri Mar 23, 2007 11:27 am
Location: Sussex, UK.

Re: TOKEN macro and sub-macros

Post by Blakey »

I can see what you mean wolph, and yes that should be 'do able'. The thing is though I am trying to re-use a huge number of Lib macros already written, without having to rewrite all the macros on the Lib token.

If I set up a Campaign macro and use it, then the token context is passed into all the lower sub-macros. I want this same behaviour to occur when I call a macro on a frame basically.

I'm guessing it isn't going to work though. :(

Blakey
The guy in the green hat.

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

Re: TOKEN macro and sub-macros

Post by wolph42 »

I had a feeling you're answer was going to be along these lines. You might want to check out aliasmask his signature look for macroIO. I have no experience with is but this might help you along that way.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: TOKEN macro and sub-macros

Post by Craig »

Wiki: macroLink() and Wiki: macroLinkText() both accept a target parameter -- the last parameter -- which is the target tokens to run the macro against. If its a single token the macro is run once, otherwise it is run each time for each target. The target token is the current token for that macro when the link is clicked. So when creating your links you just need to pass the id of the token that you want your macro to run against when the link is clicked.

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

Re: TOKEN macro and sub-macros

Post by biodude »

Craig wrote:Wiki: macroLink() and Wiki: macroLinkText() both accept a target parameter -- the last parameter -- which is the target tokens to run the macro against. If its a single token the macro is run once, otherwise it is run each time for each target. The target token is the current token for that macro when the link is clicked. So when creating your links you just need to pass the id of the token that you want your macro to run against when the link is clicked.
I was just going to suggest this: it should provide you with exactly what you need: token context that is persistent to called (sub-) macros.

On the subject of token context and current token, here are a few points I have learned along the way:
  • The effects of Wiki: switchToken() only last until "the end of the current token", which in practice essentially means the exact same scope as local variables.
  • If you want a macro to have the same currentToken as the macro that called it (higher up the chain), you can make it a user-defined function, and give the last parameter a '0', so it has the same variable (and token) context. In this case, when the macro is called as a function, it will have the same currentToken as the macro that called it, even if Wiki: switchToken() or [token:] was used.
  • If you don't want to make it a function, a similar effect can be achieved by using Wiki: evalMacro() around your macro calls (the same as execMacro, but without creating a new variable scope). Note that the [macro:] roll option normally creates a new variable (& token) scope, but not if it is used within an evalMacro function:

    Code: Select all

    [H: var = evalMacro( '[R, MACRO( "subMacro@this" ): args ]') ]
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Blakey
Dragon
Posts: 778
Joined: Fri Mar 23, 2007 11:27 am
Location: Sussex, UK.

Re: TOKEN macro and sub-macros

Post by Blakey »

Craig wrote:Wiki: macroLink() and Wiki: macroLinkText() both accept a target parameter -- the last parameter -- which is the target tokens to run the macro against. If its a single token the macro is run once, otherwise it is run each time for each target. The target token is the current token for that macro when the link is clicked. So when creating your links you just need to pass the id of the token that you want your macro to run against when the link is clicked.

Craig, that is excellent. :D

That hugely simplifies all my macro calls, enables me to re-use all my (well, Veggie's to give credit where due) library of functions, and stops me having to pass token names back and forth. Using macroLink is going to make my framework come to life!

Thanks heaps!!
Blakey
The guy in the green hat.

Post Reply

Return to “Macros”