Search Unity

Tip to avoid bug joining strings in Javascript for Metro Apps

Discussion in 'Windows' started by yoonitee, Sep 11, 2013.

  1. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Hi,

    If anyone's having trouble compiling a Javascript app for Metro here's my tips:

    1) If it doesn't compile at all with some error about "boo.lang" versions 2.0.9.5 (which it might do if you've upgraded your project form 3.x to 4.x):

    In Visual Studio delete:
    boo.lang.dll
    unityScript.lang.dll

    from the references.

    2) All the places where you have joined strings with a "+" change it to use String.Concat:

    Code (csharp):
    1. var a:String="Hello ";
    2. var b:String="World!";
    3. var c:String=a+b; //Will fail when building for Metro!!!!
    4. var c:String=String.Concat(a,b);// Will work!!!
    This is a strange bug. I would be interested just what caused this bug!!! It took me over 3 hours to work out why my app was failing!!! And it's not easy to go over all your code to check if any of your "+"'s are actually string concats so it would be nice for a fix!

    3) Or on the other hand just use C#.

    I have raised this to Unity as a bug. But hope this helps other people. If you have any other tips write them below.
     
  2. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Also another tip is that use:

    myarray.Length

    not

    myarray.length

    If you do all these things right then managedAssemblies.txt should not contain boo.lang.dll or unityScript.lang.dll and it should pass windows certification.

    But it's a bit of a hassle so its must better to use C sharp if you can.
     
  3. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Another tip is to use

    function foo(s:String){
    }

    instead of just
    function foo(s){
    }

    I think basically anywhere that the compiler could get confused with the syntax of adding strings etc. and it has to revert back to it's javascript/boo methodology will cause problems. Hopefully, this will all be sorted out in a future version.