Author Topic: String - Embedded Line Feed  (Read 574 times)

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
String - Embedded Line Feed
« on: December 22, 2010, 03:29:29 am »


               Does anyone know if there's a way to embed a line feed into a text string? An example would be: to set and use a custom token for all or part of a journal entry, consisting of two paragraphs separated by line feeds.
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #1 on: December 22, 2010, 03:32:39 am »


               Yup, there certainly is!


[color="#ffffff"]\\n[/color]

I'm pretty sure that's all you need to add. * Forum is adding a double slash. It's only one \\, followed by the n.

Thing is, you can put a line feed into a journal by hitting the RETURN key. Am I missing something?

FP!
               
               

               


                     Modifié par Fester Pot, 22 décembre 2010 - 03:37 .
                     
                  


            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #2 on: December 22, 2010, 03:45:59 am »


               

Fester Pot wrote...

Yup, there certainly is!


\\n

I'm pretty sure that's all you need to add. * Forum is adding a double slash. It's only one, followed by the n.


Hmm. I tried that and it didn't work. Let me check it again -- maybe I did something wrong.

Thing is, you can put a line feed into a journal by hitting the RETURN key. Am I missing something?


Yes, though I probably need to explain more to make it clear. I'm experimenting with controlling the entire journal entry from a script, and setting the custom token with the full text I want to appear in it (including paragraph formatting). So for example, a journal entry might simply consist of the following:


<CUSTOM5017>

Where I've set the text for custom token 5017 to something like the following (this is entirely made up):

Day 1: I Went to the market.

Day 2: I visited Uncle Jim.


And which I don't want to appear as:

Day 1: I Went to the market. Day 2: I visited Uncle Jim.


My tests are borne to some extent out of frustration with the (to me, very un-useful) way in which journal entries aren't cumulative. If you want prior state information not to be lost, you need to re-enter it; and if you decide to edit it, you need to edit it in every state where it appears. I'm experimenting with a custom quest state system with scripts that handle all of this automatically through string variables and custom tokens. It seems to work pretty well so far except for the formatting. I can probably solve that if I can manage to embed that in the text.
               
               

               


                     Modifié par AndarianTD, 22 décembre 2010 - 03:53 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #3 on: December 22, 2010, 03:56:51 am »


               Alright, so there is more to this. I'm using the \\n myself and you are right, it is a custom token.

Place this on your OnModuleLoad event. I'm sure it could go elsewhere but that's where I set my custom tokens.


SetCustomToken(1111, "[color="#ffffff"]\\n[/color]");

From there, you can use \\n in SetDescription, and even string sString = "blahblah" within scripts themselves.

blah \\n blah in conversations themselves.

As mentioned, it's one slash followed by n and you may set the value of the SetCustomToken to whatever number you require.

Be warned that using the custom token to create a RETURN will require some patience on your end to properly enter the correct number of RETURNs.

As an example, in Fate of the Auren, I read the entire database to find out what the player did in Almraiven and Shadewood, who they killed, what spirits they helped, to create a history of their life in the Land of the Living. So although there are TWO of these \\n in the SetDescription of a print out of the player's living history, it not always displays as TWO RETURNS but more. I've never been able to figure it out.

If you're looking to use this in a description to set on an item, here's an example.


if (GetCampaignInt("Almraiven", "almraiven") == 1) // COMPLETED ALMRAIVEN
        {
        string sDescription = GetDescription(oHistory);
        sDescription += "\\n \\nYou journeyed to Almraiven and ... \\n \\n";
        SetDescription(oHistory, sDescription);
        }

if (GetCampaignInt("Almraiven", "faliscomp") == 1)

      {
      string sDescription = GetDescription(oItem);
      sDescription += "Left Almraiven with Falis Goodmane, a Fighter travel companion. \\n \\n";
     SetDescription(oItem, sDescription);
     }

When appending to an already existing entry, such as a journal or a description of an item, you'll want to use the GetDescription function to snag what already exists, followed by appending the new description to the existing description.

FP!
               
               

               


                     Modifié par Fester Pot, 22 décembre 2010 - 04:08 .
                     
                  


            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #4 on: December 22, 2010, 04:05:09 am »


               

AndarianTD wrote...

Hmm. I tried that and it didn't work. Let me check it again -- maybe I did something wrong.


Never mind -- it was just a coding error, as I should have suspected. It's working perfectly now. Thanks! '<img'>
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #5 on: December 22, 2010, 04:38:29 am »


               FP, thanks for the added feedback. I already use custom tokens extensively in Sanctum (I'd never have managed the gender choosable pronouns for male and female Robin without them), so I've had a lot of practice with setting and using them. Am I understanding correctly that you're suggesting using GetDescription to retrieve a journal entry? Will that work? If it will, then it might make my job a lot easier.

Here's the idea I'm working on. I have a set of states that quests can go through (but may not in every case) -- for example, rumored, accepted, completed, etc. Each possible quest has a two-digit number, and each possible state a one digit number. I designate a range of custom tokens (for example, 5000 thru 5999) to correspond to the various quest related journal entries. So for example, the text for quest 12, state 7 would be custom token CUSTOM5127. String arrays initialized at module start and lookup functions map the journal tags and text to the quest numbers. APIs for my quest system set the tokens when called, and each journal entry simply includes the accumulated tokens that have been set. They also allow concatenating text for special cases if needed.

So for example, if the player went through states 1, 5, and 7 for quest 12, and completed the quest in state 7, then the journal entry for state 7 would look as follows:

<CUSTOM5127><CUSTOM5126><CUSTOM5125><CUSTOM5124><CUSTOM5123><CUSTOM5122><CUSTOM5121>

But all these strings would be null except 1, 5, and 7, which would start and end with a backslash n. The result is a nicely formatted section for each state, set off by a paragraph break, most recent first, and only including the history  that the player's quest path actually took him through. I'm hoping that will help me to handle cases where for example you complete a quest before meeting the quest giver, and still have the journal accurately reflect what the player actually did. At least that's the idea. '<img'>
               
               

               


                     Modifié par AndarianTD, 22 décembre 2010 - 04:41 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #6 on: December 22, 2010, 05:56:16 am »


               Hmmm,



Is this going to be for a single player or multi player module.  



If it is a multi Player module. There are some things that may make this unworkable for you.



Here is how the journal works with custon tokens.  



-The custom token is set in the memory of the server.  

-When the client opens the journal it checks to see if any of then entrys are new.  

-If one is new. the client sends a quire to the server for the journal entry.

-The client does not recive any token information.  It only recives the string that the entry needs to be set to.  



-If when the client opens the journal old entrys will not be upated to new token values.

-For new journal entrys the tokens will be given the value of the token when the player opens there journal.  Not the value of the token when the entry is modified by script.



Now if the token value are going to be the same for all players in the game it can work.  It is just that every time you change the value for the token, you will need to remove then add the entry back to everyones journal.  



               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
String - Embedded Line Feed
« Reply #7 on: December 22, 2010, 12:59:32 pm »


               

Lightfoot8 wrote...

Is this going to be for a single player or multi player module.

If it is a multi Player module. There are some things that may make this unworkable for you.


Understood. I'm aware of the issues with using tokens in MP, but I only build single player modules so those aren't a problem for me.

Here is how the journal works with custon tokens...

 

*Nods* I already use custom tokens extensively (including in journals) in my current modules (though not on as large a scale as I'm thinking of doing now), so I understand how that works. It was getting the embedded formatting to work that I was having trouble with, and as it turns out that was my own fault. But I thought I'd share the idea for the system I'm experimenting with to get feedback, and in case others might find it interesting.

As I said I find some aspects of the current journal / quest system to be problematic and error prone, and wanted to see if I could code something that would help. The two things that I've always found awkward are to carry forward text from previous journal states (which I often find it necessary to do to maintain an accurate quest history), and to handle cases where quests are done out of order or with some of the optional state transitions missing. It really is easy to mess those things up, and some of the common avoidance mechanisms for them are cumbersome and contrived, and I'm hoping this approach will let me handle some of that. I'll let you all know how it works out. '<img'>
               
               

               


                     Modifié par AndarianTD, 22 décembre 2010 - 01:01 .