Page 1 of 1

Newlines in new macros

Posted: Tue Jun 29, 2010 10:41 pm
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.

Re: Newlines in new macros

Posted: Tue Jun 29, 2010 11:10 pm
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" ]

Re: Newlines in new macros

Posted: Tue Jun 29, 2010 11:21 pm
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!

Re: Newlines in new macros

Posted: Wed Jun 30, 2010 12:22 am
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.

Re: Newlines in new macros

Posted: Wed Jun 30, 2010 1:18 am
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.

Re: Newlines in new macros

Posted: Wed Jun 30, 2010 1:25 pm
by Raoden
Eh, I didn't think of it either until someone on the Forum (Azhrei?) suggested trying it.

Re: Newlines in new macros

Posted: Wed Jun 30, 2010 2:07 pm
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 = "
"]

Re: Newlines in new macros

Posted: Wed Jun 30, 2010 7:18 pm
by Azhrei
I agree with AM. I would decode the %0A and store it in a variable to be used throughout the macro...