Newlines in new 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
bmceldowney
Kobold
Posts: 8
Joined: Mon Jun 28, 2010 9:35 pm

Newlines in new macros

Post by bmceldowney »

I have some code to generate a macro command.

Code: Select all

  [h:newEntry = '[h:weapons = json.append(weapons, json.set("{}", "index", json.length(weapons), "name", "' + name + '", "subtype", "", "damage", ' + damage + ', "qualities", json.append("", "' + list + '")))]']
  [h:output = concat(substring(command, 0, index - 1), newEntry, substring(command, index - 1, length(command)))]
  [h:setMacroCommand(macroIndex, output)]

I would like the resulting macro to look decently readable with new lines in the right places. How can I add a newline character to the macro command? I experimented with \n, but couldn't quite get the result that I am going for.

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

Re: Newlines in new macros

Post by biodude »

I wonder if this works (untested)...
Try using this code to insert a new line into text: decode("%0A")
e.g.

Code: Select all

[H: string = "line 1"+ decode("%0A") +"line 2" ]
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

bmceldowney
Kobold
Posts: 8
Joined: Mon Jun 28, 2010 9:35 pm

Re: Newlines in new macros

Post by bmceldowney »

biodude wrote:I wonder if this works (untested)...
Try using this code to insert a new line into text: decode("%0A")
e.g.

Code: Select all

[H: string = "line 1"+ decode("%0A") +"line 2" ]

That's the correct answer!

Thanks!

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Newlines in new macros

Post by Raoden »

I was also able to just literally insert a "quotation mark, 'Enter' key, quotation mark" string into a macro command in one of my projects, and it worked just fine.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

bmceldowney
Kobold
Posts: 8
Joined: Mon Jun 28, 2010 9:35 pm

Re: Newlines in new macros

Post by bmceldowney »

Raoden wrote:I was also able to just literally insert a "quotation mark, 'Enter' key, quotation mark" string into a macro command in one of my projects, and it worked just fine.

Hmm. I have no idea why that didn't occur to me. I think I need some more sleep.

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Newlines in new macros

Post by Raoden »

Eh, I didn't think of it either until someone on the Forum (Azhrei?) suggested trying it.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

User avatar
aliasmask
Deity
Posts: 8610
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Newlines in new macros

Post by aliasmask »

Raoden wrote:I was also able to just literally insert a "quotation mark, 'Enter' key, quotation mark" string into a macro command in one of my projects, and it worked just fine.

Yeah, that's an ugly solution though. I saw that trick when I was adding stuff to MacroIO. Of course, I'm of the school of thought most output should be put in variables and output at the end of the process. I'm kind of a neat freak when it comes to my code and output. I never want to say to myself, "Is that code or output?"

My personal preference would be use either the encoded %0A or the literal decode("%0A") rather than

Code: Select all

[crlf = "
"]

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

Re: Newlines in new macros

Post by Azhrei »

I agree with AM. I would decode the %0A and store it in a variable to be used throughout the macro...

Post Reply

Return to “Macros”