Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Larry-Dietz · Feb 05, 2012 at 08:23 AM · databasegui.boxnewline

Newline problem in GUI.Box when text comes from database

I am having a string problem, that really doesn't make any sense to me.

The following works as expected, including the newlines...

 string Text="This is\na Test";
 GUI.Box(new Rect(DialogWindow), Text, MySkin.box);

The above displays a box at the DialogWindow location with the following...

 This is
 a Test

Which is perfect.

Now, if instead of setting the string in code like that, I pull the exact same string from a SQLite database, it displays like...

 This is\na Test

Debugging out both the string created in code, and the string pulled from the database, they appear to be identical.

I cannot figure out why, when using the string from the database, the newline character is displayed instead of a linefeed being inserted.

Anyone else ever see this problem? Any ideas how to get this to work as expected?

Any help is greatly appreciated.
-Larry

EDIT: As a test, I just copied the text from the SQLite table, and pasted it into the hard coded string, just to make sure they were truly identical. Same results. The hard coded string works, the string pulled from the database does not.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Feb 05, 2012 at 05:52 PM

Here is an experiment for you to understand what's happening here :

Create a script with that code, put it on any object.

 var text : String;
 function OnGUI(){
     GUI.Label( Rect( 10, 100, 500, 50 ), "First line\nSecond line" );
     GUI.Label( Rect( 10, 200, 500, 50 ), text );
 }

In the inspector, fill the variable text with : First line\nSecond line. Then run, and you'll notice that the first label is ok, when the second one isn't. I know more or less where that comes from, but you'll need a pro for details. I think it's about texte formatting done by the editor (monodevelop in my case) which isn't done by unity editor, neither by your SQL apparently. To fix that, I suggest you split the sentence in your SQL into so many lines, then assemble it in your code like such :

 str = line1fromSQL + "\n" + line2fromSQL.
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Larry-Dietz · Feb 05, 2012 at 06:23 PM 0
Share

You are absolutely correct. I just tried what you suggested, and the first line displayed as expected. The 2nd displayed the newline character the same as when I pulled it from the database. So apparently the database is not the problem.

I will try to figure out the best way to break this into multiple lines in the database, and assemble them. Gonna be a bit of a trick with the way I have it setup though.

I am basically creating a data driven dialog system, and splitting this into multiple lines is going to cause some duplication in the players possible responses. So I will have to work around that also.

I think I am going to play around with string formatting a bit, and see if I can figure out what is different, and duplicate the formatting in code. Would be a lot easier all the way around if I could just get the newlines to work ;)

Thanks! -Larry

avatar image Larry-Dietz · Feb 05, 2012 at 07:16 PM 0
Share

Ok, I figured out a work-around based on your information. Just in case anyone else needs to workaround a similar problem, here is what I did.

First I substituted the | character for the newline in the database, then after getting the string from the database, I split the string on the | character, then concatenated each string in the returned array into a new string, appending "\n" to the end of each.

Using this new concatenated string, I got the results that I was expecting.

Again thanks for pointing me in the right direction!

-Larry

avatar image
1

Answer by Banemus · Aug 30, 2013 at 09:05 AM

Just do this:

             string
                 rumor_compilation;

             rumor_compilation = RumorTable[ rumor_index ].Replace( "\\n", "\n" );

             GUI.Box( new Rect( half_screen_width - 150, half_screen_height - 130 + 90 * rumor_index, 300, 90 ), rumor_compilation );


unity automatically adds an extra \\ to the \\n in there

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to connect to oracle databases for webplayers 0 Answers

Develope Cloud & Vuforia application 1 Answer

Read/Write attachments from MS AccessDB 0 Answers

Players online counter 1 Answer

how to make the build in android which can access the local database sqlite 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges