Using createMacro()

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

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

Using createMacro()

Post by Rumble »

Is it possible to embed a macro call within the command argument of createMacro()?

For instance, suppose I want to automatically create the macros for a character token, and the token button I'm creating contains only a call to a macro on a Lib:token, like:

Code: Select all

[MACRO("attack@Lib:test"):""]
How can I embed that into the following?

Code: Select all

[createMacro("Attack", [i]macro call goes here[/i], props)
I have tried many different combinations of quotes and concat() and string() and all that, but nothing seems to work. Any advice would be greatly appreciated!

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Using createMacro()

Post by Azhrei »

Make it two steps? Call the macro and keep the return value, then use that return value in the createMacro call?

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

Re: Using createMacro()

Post by Rumble »

Unless I misunderstand your suggestion, I'm not sure that will do the trick - as some background, I have a macro that generates and sets Powers for a token (so, like, you'd generate the power "Holy Strike" with all of the relevant stats calculated out, and then you can later use that power in combat). What I'm thinking about doing is this: when a player edits his or her token, and adds a power, the Power Editor macro does all the normal stuff, but also generates a macro button on the token of the appropriate color that will activate the power when clicked.

So the createMacro() line would be something like:

Code: Select all

[h: createMacro("Holy Strike","[MACRO("HolyStrike@Lib:test"):"" ", "color=green;fontColor=black;autoExec=true;")]
However, I haven't yet come to the right arrangement of quotes and concatenations to treat the MACRO("HolyStrike@Lib:test"):"" bit as plain old characters, and I get null errors or various other frustrations.

Perhaps encode() will do the trick.

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

Re: Using createMacro()

Post by Rumble »

AHA! It is indeed possible through the judicious use of encode() and decode()!

Just in case anyone else ran into this (or is just curious), this is how I did it:

Code: Select all

[h:command=encode("[MACRO('HolyStrike@Lib:test'):'']")]

[h:creatMacro("Holy Strike",decode(command),props)]
Worked out nicely.

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

Re: Using createMacro()

Post by Craig »

Rumble wrote:AHA! It is indeed possible through the judicious use of encode() and decode()!

Just in case anyone else ran into this (or is just curious), this is how I did it:

Code: Select all

[h:command=encode("[MACRO('HolyStrike@Lib:test'):'']")]

[h:creatMacro("Holy Strike",decode(command),props)]
Worked out nicely.
Its one of the things that causes some pain, the variable is read and then evaluated so if it contains [] then the parser will run what is in the []... encode/decode is one way of doing it,
another is something like

Code: Select all

[h:createMacro("Holy Strike", "["+ command +"]", props)]
and leave the enclosing [] out of the original string.

I am trying to think of a better way to do it so these kind of tricks are not required but its not coming to me immediately.

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

Re: Using createMacro()

Post by Rumble »

Craig wrote:
Rumble wrote:AHA! It is indeed possible through the judicious use of encode() and decode()!

Just in case anyone else ran into this (or is just curious), this is how I did it:

Code: Select all

[h:command=encode("[MACRO('HolyStrike@Lib:test'):'']")]

[h:creatMacro("Holy Strike",decode(command),props)]
Worked out nicely.
Its one of the things that causes some pain, the variable is read and then evaluated so if it contains [] then the parser will run what is in the []... encode/decode is one way of doing it,
another is something like

Code: Select all

[h:createMacro("Holy Strike", "["+ command +"]", props)]
and leave the enclosing [] out of the original string.

I am trying to think of a better way to do it so these kind of tricks are not required but its not coming to me immediately.
I'm not sure it needs a better way, really. Although, in my situation, it took some doing to assemble a multiple-command macro and assign it to a newly created button, once I hit on the solution it became simple. Basically, I created auto-color-changing buttons on the fly as new powers are added to the character, so I needed 3 commands - one to identify the power, one to call the power macro, and one to dim the button when it was clicked. It was a matter of adding together some encoded strings, and then it worked fine.

Your additions to b48 have been stellar and have opened up huge potential, by the way - I've been able to do some really impressive (if I do say so myself :)) things with the stuff you've built into this latest version. Thank you!

Post Reply

Return to “Documentation Requests/Discussion”