Search Unity

Using unicode (UTF-8 / UTF-16) script in MonoDevelop

Discussion in 'Editor & General Support' started by Dakwamine, Jan 3, 2013.

  1. Dakwamine

    Dakwamine

    Joined:
    Aug 5, 2012
    Posts:
    21
    Hi all,

    When I try to use MonoDevelop to make my scripts, I have a strange behaviour with "foreign" characters like those of french or chinese languages.

    If I make a simple script with:

    Code (csharp):
    1. string s = "Je suis une phrase en français.";
    2. string chinese = "我是一个中国人的一句。";
    3. string arabic = "أنا العبارة العربية."; // Don't bother about RTL stuff, it is just a test
    4.  
    5. Debug.Log (s);
    6. Debug.Log (hindi);
    7. Debug.Log (arabic);
    I am getting this in console (or GUI):

    Even if I set UTF-8 in the save options of the file, it doesn't change anything. But if I set a character encoding that cannot handle the characters from the script, for example the Western ISO one, when saving, MonoDevelop will ask me if I want to resave using Unicode. If I say yes, then that's what I get in console:

    So my first question is : why should I choose an incorrect encoding in order to have the correct encoding in the end?

    My second question is about the UTF-16 encoding: whenever I try to use this, I have a parse error in the editor (Assets/Unicode2.cs(1,5): error CS8025: Parsing error). Does Unity supports UTF-16 or not?

    At the moment, I use Visual C# which is less buggy about this problem.
     
  2. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Try JS,or utf8+bom

    ps:Windows?
     

    Attached Files:

  3. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    I done experiment with your code. What i does i put all you string variables in onescript made with notepad++ and save As UTF-8. I changed all your string variables to public static and access all variables from another script and now i can see all variable as it in console window when i try to print.

    if i open the script which i made in notepad++ in monodevelop, then its show again wrong character in console window. Show never open that script with monodevelop.
     
  4. Dakwamine

    Dakwamine

    Joined:
    Aug 5, 2012
    Posts:
    21
    Where can I set the BOM in MonoDevelop? I can only see the UTF-8.

    I'm on Windows and I would like to stay on C# language because I prefer it to JS. So is it better to develop on Mac?

    I know this is a good solution for character encoding problems (to use Notepad++). But at the moment, I am making an editor script with a lot of "plain" strings (not in variables). As those strings helps me to locate myself in the script, I am not willing to use that method.

    But what I have found is that when I make a special manipulation in MonoDevelop, the scripts in MonoDevelop works perfectly in UTF-8. Like it was a hidden saving functionality...

    The secret manipulation as described above:
    1. File > Save As...
    2. Character Coding: "Western ISO-8859-15" or whatever coding which does not support your strings characters
    3. Click "Save" button
    4. Click "Overwrite File" button
    5. Click "Save as Unicode" button
    6. Your file is correctly saved as UTF-8 for Unity! Now, even if you save the file again with the Save Ctrl+S command, the script will correctly show the good characters in the editor.
    If at the last step, MonoDevelop was not saving the file correctly for Unity, I would just say: "MonoDevelop does not support UTF-8 for Unity, end of story". But here, MonoDevelop can actually save in Unity's UTF-8, and what I have to say is that the saving feature is not consistent...:mad:

    So it seems that MonoDevelop is just bugged on that point. Is it not?
     
  5. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
  6. Dakwamine

    Dakwamine

    Joined:
    Aug 5, 2012
    Posts:
    21
    How do you use UTF-16 in MonoDevelop? When I set UTF-16 character coding in the save box of my scripts, I get a parsing error in Unity's editor.

    Or do you mean using another text editor to write UTF-16 text and then copy/paste into the script?
     
  7. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    I use Unitron instead of MonoDevelop. I set Unitron to open in UTF-8 (I use JS instead of C#) using Preferences. I assume similar principles work in MonoDevelop / C#.
     
  8. Dennis Roseman

    Dennis Roseman

    Joined:
    Dec 17, 2012
    Posts:
    4
    My problem seems very similar to this .
    I have tried the various remedies to save with notePad++, MonoDevelp with no effect. (Code saved with UTF-16 in MonoDevelop seems not readable in Unity.)

    I am using C# and MonoDevelop and have problems with lines like:

    Code (csharp):
    1. myTextMesh.text = "Ñ"; // a one letter string of a Capital N with a tilde
    If I just copy and paste Ñ (from part of a script in MonoDevelop) in the text field of myTextMesh using Unity
    Editor it comes right out on my mesh.So I have imported my font correctly, I think.

    I am adopting my word game to Spanish and I really need to be able to handle this (and similar font problems)
    in C#, not cut-and-paste.

    Below three completely self contained lines of code below, copied and pasted from MonoDevelop and the
    console output.

    what do I need to do to make that first line come out with Ñ and not Ñ?


    Code (csharp):
    1. Debug.Log("Well OK so  Ñ looks like what when printed??");
    2. char daString ='\u00D1';  
    3. Debug.Log(" Another thing to try is : "+daString.ToString());
    4.  
    .....and in the console, in detail, it comes out like this:

    Well OK so Ñ looks like what when printed??

    Another thing to try is : Ñ
     
  9. Dennis Roseman

    Dennis Roseman

    Joined:
    Dec 17, 2012
    Posts:
    4
    OK I tried to save again with Notepad++ and this time it works---
    In the encoding Tab I needed to CONVERT to UTF-8 not just use UTF-Encoding and Save

    anyhow, problem solved..

    Dennis
     
  10. Gurc

    Gurc

    Joined:
    Jul 9, 2012
    Posts:
    43
    Yep, this is the real solution.
     
  11. nikola82

    nikola82

    Joined:
    Oct 24, 2012
    Posts:
    1