SetMacroProps, GetMacroProps,JSON, and semi-colons oh my!

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
Cave Troll
Posts: 90
Joined: Fri Aug 08, 2008 11:19 pm
Location: South Florida, USA

SetMacroProps, GetMacroProps,JSON, and semi-colons oh my!

Post by Zalarian »

I was hoping some folks out there could help me with a library token I am working on. A while back, I worked on a campaign file that merged 2 campaign file frameworks together (Veggie and DN) but gave up on it due to the messiness that ensued when managing states between the frameworks. Some time passed and some other folks did a similar task (Not sure exactly who gets credit for that: My initial guess is mr0bunghole and Xalcairn). I have since added additional changes such as performing the necessary work to make the majority of the Veggie token states accessible from the DN framework. The next step is to be able to convert Veggie tokens that primarily have generated code with states in macros to use the DN tokens. Additionally, the capability of converting the converted token back in use as a Veggie token. This would then allow players to use whichever framework they prefer by converting states if using a Veggie token and it would also allow judges to take a preexisting campaign file, update the framework to allow both frameworks and if necessary convert the Veggie monster tokens to use the available new token states. I also realize that there is active coding being done on the DN framework so when that is in a more polished form, the hybrid framework can be updated then.

Tokens between the two frameworks use different states. For regular games that have a fixed rotation of judges and players this is not an issue since the GMs primarily choose the framework. However in living campaigns this causes challenges as people create adventures and get people to sign up for games using the various frameworks. I would like a macro to be run on the tokens built using the veggie framework and replace the code generated in macros there with states recognized in the states being present.

The current code used to get and set the command string (setMacroProps and setMacroProps) has issues with semicolons due to the requirement of using json. Currently, the code performs the necessary replacement before the first semicolon and all other code is removed.

Here is a code snippet which used biodude's post about Batch Edit Macro properties. I am also attaching the current copy of my library token here.

Code: Select all

[H, FOREACH( loc , targetLocations ), code:{
   [H: switchToken( loc )]   <!-- Not entirely necessary, but helpful -->
   [if (getName( loc ) == "Lib:VegStateConverter"): abort(0)] <!-- Do not allow to Library to be updated -->
   [H: updateMacros.list = "" ]
   <!--   Build list of macro INDICES (needed for getMacroProps )   -->
   [H: macros.list = getMacros( "json", loc ) ]
   [H: macroName.index = "" ]   <!-- to allow later lookup of name by index ( for output ) -->
   [H: macroIndex.list = "[]" ]   <!-- empty json array -->
   [H, FOREACH( macro, macros.list ), code:{
      [ index.macro = getMacroIndexes( macro, "json", loc )]
      [foreach( macroIndex, index.macro ): macroName.index = json.set( macroName.index , macroIndex , macro )]
      [ macroIndex.list = json.merge( macroIndex.list, index.macro )]
    [x = ""]
   [H: macroIndex.list = json.unique( macroIndex.list )]
   [H: editMacro = 0 ]   <!-- default: do not edit macro.  Check if conditions match to approve editing -->
   [FOREACH( macroIndex, macroIndex.list ), code:{
      [ macroProps = getMacroProps( macroIndex, "json", loc )]
      [ = json.get( macroProps, propName ) ]
      [macroProps.old = json.get( macroProps, propName ) ]
      <!----Begin Code here to do replacements   --->

      <!----code for semicolon testing    x "aaa" ; y "aaa" z--->
      [ = replace(, '"aaa"', '"bbb"') ]

      <!----snipped replaement code in sample -->
   <!----End Code here to do replacements   --->
      [if ( == macroProps.old): editMacro = 0 ; editMacro = 1]
      [if ( editMacro ): = "command=" +]
      [if ( editMacro ): updateMacros.list = listAppend( updateMacros.list, json.get( macroName.index, macroIndex ) )]
      [if ( editMacro ): setMacroProps( macroIndex,]
      [if ( editMacro ):x = macroProps.old + "<br>.:"]

   [H: messageOut = strformat( outputMessage, if( updateMacros.list=="" , "NONE" , updateMacros.list ) )]
   [H: outputText = strformat( outputFrom , getTokenImage( 40 ) , getName( loc ) , messageOut )]
   [H: allOutput = allOutput + outputText + "<br>"]


Any help in this matter would be greatly appreciated.

Batch Edit Macro Properties [1.3b56+]

4e interactive sheet & utilities (DN)

Veggiesama's Framework (D&D 4e) (Veggie)

Living Campaigns
(41.9 KiB) Downloaded 41 times
Last edited by Zalarian on Tue Jul 06, 2010 2:06 pm, edited 1 time in total.

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

Re: SetMacroProps, GetMacroProps,JSON, and semi-colons oh my

Post by biodude »

I'm not familiar with the frameworks you're working with, but maybe I can comment on the metamacro code ;)
(BTW, a lot of that macro editing code is 'borrowed' from Rumble's batch macro deletion / copying macros, which I built on).

I am most concerned about this line:

Code: Select all

      <!----code for semicolon testing    x "aaa" ; y "aaa" z--->
      [ = replace(, '"aaa"', '"bbb"') ] 

macroProps is a json object, which contains ALL the properties of the current macro in the loop (see [wfunc]getMacroProps[/wfunc]). It's also a json, not a string, which makes me nervous (it does not generate an error, surprisingly, but I still would not trust it). If you only want to change the command, I would extract that explicitly first, and run the replace on that, before putting it back in:

Code: Select all

      [macroCom = json.get( , 'command' )]
      [macroCom = replace(macroCom, '"aaa"', '"bbb"') ]
      [ = json.set( , 'command' , macroCom )] 

Hope this helps, and sorry no one responded for so long.
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Cave Troll
Posts: 90
Joined: Fri Aug 08, 2008 11:19 pm
Location: South Florida, USA

Re: SetMacroProps, GetMacroProps,JSON, and semi-colons oh my

Post by Zalarian »

biodude wrote:Hope this helps, and sorry no one responded for so long.

Thanks! I knew something was odd and that seemed to be what I needed to correct the issue. I will likely update my code since the way I have it working is not very efficient due to nesting limitations.

Post Reply

Return to “Macros”