View Full Version : Newline character screwing MGlobal?

03 March 2009, 10:38 AM
Hi all,

I'm currently in the process of converting a prototype, of a program I wrote in Python, into a C++ plugin. But I've come across a weird problem, parts of my program feed data back into a scrollField in an output window I created, but the newline character seems to be causing an 'Unterminated string' error. This is the offending command:

MGlobal::executeCommand("scrollField -e -ip 0 -it (\"\n\
Simulation started.\") openEchoScroll;"));

And this is the error from the script editor:

// Error: scrollField -e -ip 0 -it (" //
// Error: Line 1.28: Unterminated string. //

But this is crazy because I get no compiling errors, and when I copy the code into the script editor manually (and remove the escape characters from the apostrophes), it works perfectly!

Any suggestions?

Robert Bateman
03 March 2009, 10:59 AM
It's not the \n, it's the actual newline in your string. This is why when you move it onto 1 line (i.e. remove the newlines) it works.

03 March 2009, 11:35 AM
Well, I moved it onto one line...

MGlobal::executeCommand("scrollField -e -ip 0 -it \"\n-------------------------------------\nSimulation started.\" openEchoScroll;");
...and the same error.

But I got it to work by removing all the '\n' symbols, leaving just the line continuation slash and actually putting the code on a new line in my IDE, and removing the white space before the new lines:

MGlobal::executeCommand("scrollField -e -ip 0 -it \"\
Simulation started.\" openEchoScroll;");
Thanks anyway!

03 March 2009, 12:10 PM
Actually no, I was wrong. That method doesn't result in newlines, which seems kind of obvious now I look at it...

Well now I'm totally stumped, I'm using VS2008 at school at the mo, do you know of any string quirks that it has?

03 March 2009, 07:44 PM
Just to be sure I built a wchar_t version of it, with the \n symbol changed for \0x0a - the Unicode equivalent.

wchar_t scrollUp[] = L"scrollField -e -ip 0 -it \"\0x0a-------------------------------------\0x0aSimulation started.\" openEchoScroll;";
That didn't work, exactly the same error. What's really weird though is if I try my original formatting style but with the MGlobal::displayInfo() command:

Simulation started.\n");
This works perfectly! Why the difference between the way executeCommand() and displayInfo() handle strings?

03 March 2009, 01:02 AM
This works!

MGlobal::executeCommand("scrollField -e -ip 0 -it \"\\n\
Simulation started.\\n\" openEchoScroll;");
Must be due to the way the characters in the 'inner' string are effectively parsed twice.

CGTalk Moderation
03 March 2009, 01:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.