Trouble getting newlines in journal through scripting


I am trying to manipulate journal entries through scripts and custom tokens. I would like to place a couple of line breaks between entries, so I am putting two consecutive \n\n at the start of each string. For example: “\n\n This is my second entry”. But the \n\n prints in front of the text instead of converting to new lines. So I get something like

This is my first entry.\n\n This is my second entry.

Any help is appreciated!

How do you define journal entries via script?

The solution is quite simple, create a placeable “Linefeed” and place it into the module. The description has only one character, a linefeed (hit return once).

The following code will generate the shown output with a linefeed:
SendMessageToPC (GetFirstPC(), “a”+GetDescription(GetObjectByTag(“LineFeed”))+“b”);


Mmat, thanx for the reply.

To clarify…I need nwscript for dummies lol…

So if I wanted to send this string to a journal entry via custom token, the string the custom token is set to would be

string sToken="This is my first entry. " + GetDescription(GetObjectByTag(“LineFeed”))+GetDescription(GetObjectByTag(“LineFeed”))+“This is my second entry”

After setting the appropriate token and referencing it in the journal, I would get…

This is my first entry.
blank line
blank line
This is my second entry.

Note I am just using “blank line” to clarify two empty lines. Nothing is really there.

I see. Well, it works … (The LogEntry reads “<CUSTOM555>”)

void main()
string linefeed = GetDescription(GetObjectByTag(“LineFeed”));
string message = “a”+linefeed+linefeed +“b”;
SetCustomToken (555, message);
AddJournalQuestEntry (“test”, 1, GetFirstPC());

The \n\n method works for me.

Here’s an example. It’s a bit long-winded, as it’s the first one that came to hand, but you see that in essence it builds a string which is then inserted in the custom token before updating the journal. In the journal entry it appears as


The script is

void main()
  object  oPC                  = GetFirstPC();
  int     bAstonCastleCutscene = GetLocalInt(GetObjectByTag("trCutsceneAstonCastle"), "OneOffDone");
  int     bGuildhallScene      = GetLocalInt(GetObjectByTag("MayorHogsbottom"), "DoOnceintro");
  string  sText                = "HOUSE ROYSON"
                               + "\n\nQueen Anne has been appointed Regent with the support of the Roysons and Fitzwilliams, in view of King Henry's mental incapacity.";

  if (bAstonCastleCutscene)
    sText = sText + "\n\nHer affinity holds the South."
                  + "\n\nLara Fitzwilliam's estates near Amesbridge in the North are surrounded by Evenlode supporters.";

  if (bGuildhallScene)
    sText = sText + "\n\nFitzwilliam supporters have begun to seize farms in the Astonbridge district."
                  + "\n\nKing's Justice Hogsbottom is powerless to confront the Fitzwilliams, but has referred the matter to the High Court.";

  sText = sText + "\n\nHOUSE EVENLODE"
                + "\n\nRichard Evenlode, Earl of Silbury, is concerned that the Queen's affinity have become a law unto themselves."
                + "\n\nLady Constance Caraway agreed to help him lobby for justice.";

  if (bAstonCastleCutscene)
    sText = sText + "\n\nHowever, this plan failed with her cousin, William Caraway, who remains undecided after his wife, Margaret Fitzwilliam, turned their meeting into a confrontation hetween mages."
                  + "\n\nHouse Evenlode holds the Midlands."
                  + "\n\nWilliam Caraway may be the key to the divided North.";

  if (bAstonCastleCutscene)
    sText = sText + "\n\nMAGES"
                  + "\n\nEvidently, there are at least two orders of mages in town."
                  + "\n\nSelene Moonglow of the Perfect Circle seems to be working for Margaret Fitzwilliam."
                  + "\n\nJasper Rookfield of the Seventh Veil is employed by Lady Constance Caraway.";

  SetCustomToken(37, sText);
  RemoveJournalQuestEntry("jt_background", oPC);  // Must do this because custom token is baked in
  AddJournalQuestEntry("jt_background", 1, oPC, TRUE, FALSE, TRUE);

It’s somewhat astonishing, that the engine translates the custom token, but not the escape code. However I didn’t check, I just believed the OP.

Well, this approached worked for me… sort of…

I was getting very frustrating compiler errors if I put the function call in exactly by cutting and pasting. It was giving me an undefined variable error. After a lot of systematic testing and hair pulling I discovered that it did not compile with ANY litteral string in the GetObjectByTag() call. If I put the “LineFeed” into a declared variable string sLF and put the variable in the GetObjectbyTag call it worked fine for me


string sToken="This is my first entry. " + GetDescription(GetObjectByTag(“LineFeed”))+GetDescription(GetObjectByTag(“LineFeed”))+“This is my second entry”

will not compile. yields error that variable is not defined.

string sLG=“LineFeed”;
string sToken="This is my first entry. " + GetDescription(GetObjectByTag(sLG))+GetDescription(GetObjectByTag(sLG))+“This is my second entry”

works great!

Added info: I do not know if this makes a difference by my functions for building the tokens are in an #include file. They are called from an action taken script.

Thanx for the help… I also will be sending a reply to your \n\n response below.

The \n\n method works for me.

Weird, this is almost exactly the format of my text calls. The only difference I see is I keep all my text on one long line. I did not know you could break up the concatenation over multiple lines like you do. Makes for much better readability. The other difference is that I am using a token with a much higher number. i.e., CUSTOM170002. I don’t know if there is some weird collision going on - using CEP3.1.

My nwn tookset seems to have some flaws that your not experiencing. But since I have a working approach, I am not going to investigate further for now.

Thanx again!

Oh, another difference is that my text is retrieved from other tokens using a modified GetCustomToken() call I found on NWN Lexicon called GetCustomTokenEx(). Maybe that call does something to the escape character in the string… converting them to literal characters?

It compiles perfectly if you watch out the quotes. The forum software sometimes changes quotes into typographical ones. Look Closely on the quotes around “LineFeed”.

Ugh… that might be it exactly. When I have some time, I might try testing that idea out. Funny, I cut and paste to avoid typos… never thought I had to worry about problems with cut and paste.

You guys are all so much help… and so patient!


See Lexicon topic string.

The original problem sounds like a string literal longer than 511 characters.

Escape characters like \n will work in any string created in nwscript.

I am aware of the literal limit of 511. The individual literals are 80 or less. There is one concatenation that I put in a variable that might get close to the 511 limit. I’ll have to check on that, but I thought when you concatenate string builds into a variable you could increase string length quite a bit. Still, I’ll do a clean test module with no haks to explore the situation a bit. I’ll first try reproducing the SendMessagetoPC code by Mmat, then the journal entry code you have and satisfy myself there is nothing in my module causing weirdness.

Correct. An nwscript string variable can be enormously long (millions of characters) though performance eventually degrades.