x


JScript problem

hi,

I have a weird problem. I sometimes need to import Blender Shape keys into Unity, and I always used MetaMorph developed by Foolish Frost without problem. In one recent project, however, I got tons of compiling errors. I finally got around by modifying an old project with a working MetaMorph script into the new one. But the problem kept gnaw at me and I feel uneasy not knowing what's wrong. I included both the error messages from one function and the corresponding function definition below. Hopefully someone can tell me what's wrong.

Jason

-----CompilerOutput:-stderr---------- -----EndCompilerOutput--------------- - Finished compile Library/ScriptAssemblies/Assembly-UnityScript-firstpass.dll Assets/Standard Assets/Scripts/MetaMorph.js(311,74): BCE0019: 'length' is not a member of 'Object'.

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 311)

Assets/Standard Assets/Scripts/MetaMorph.js(313,96): BCE0048: Type 'Object' does not support slicing.

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 313)

Assets/Standard Assets/Scripts/MetaMorph.js(318,98): BCE0048: Type 'Object' does not support slicing.

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 318)

Assets/Standard Assets/Scripts/MetaMorph.js(329,70): BCE0004: Ambiguous reference 'parseFloat': UnityScript.Lang.UnityBuiltins.parseFloat(double), UnityScript.Lang.UnityBuiltins.parseFloat(int), UnityScript.Lang.UnityBuiltins.parseFloat(String), UnityScript.Lang.UnityBuiltins.parseFloat(float).

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 329)

Assets/Standard Assets/Scripts/MetaMorph.js(331,97): BCE0048: Type 'Object' does not support slicing.

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 331)

Assets/Standard Assets/Scripts/MetaMorph.js(336,101): BCE0004: Ambiguous reference 'parseFloat': UnityScript.Lang.UnityBuiltins.parseFloat(double), UnityScript.Lang.UnityBuiltins.parseFloat(int), UnityScript.Lang.UnityBuiltins.parseFloat(String), UnityScript.Lang.UnityBuiltins.parseFloat(float).

(Filename: Assets/Standard Assets/Scripts/MetaMorph.js Line: 336)

Assets/Standard Assets/Scripts/MetaMorph.js(369,66): BCE0048: Type 'Object' does not support slicing.

 function ReadAnimationFile(datafile : TextAsset) : Array
 {
     // This read blender 3d ShapeKeys that have been exported with the diffmap.
     // It's a good idea for each animation to contained in it's own file under it's own name.
     Report("Loading Animation Recording: " + datafile.name, 2);
     var Animation_Array = new Array();
     //var Total_String = datafile.text;
         
     var Total_Array = new Array();
     Total_Array = datafile.text.Split("\n"[0]);
     
     var line : int;
     for ( line = 0 ; line<Total_Array.length ; line=line+1 )
     {
         var Line_String : String = Total_Array[line];
         
         // parse out all the crap.
         var boo = Regex.Match(Line_String,"(\\[|\\])");
         if (boo.Success)
         {
             Line_String = Regex.Replace(Line_String,"(\n|\r|\f)","");
             Line_String = Regex.Replace(Line_String,"(\\[|\\])","");
             Line_String = Regex.Replace(Line_String,"\\s*(,)\\s*","|");
             Line_String = Regex.Replace(Line_String,"'","");
             
             var Line_Array = new Array();
             Line_Array = Line_String.Split("|"[0]);
             
             var item : int;
             
             // We really want the floating point numbers to be stored as floating points, and not strings...
             if (Animation_Array.length == 0)
             {
                 Animation_Array.Add(Line_Array);
                 
                 var Line_Array2 = new Array();
                 for ( item = 0 ; item<Animation_Array[0].length ; item=item+1 ) // Line 311
                 {
                     var Found : int = FindName( Diff_Maps, [Animation_Array[0][item]] ); // Line 313
                     if ( Found != -1)
                     {
                         Line_Array2.Add(Found); // Writing line two, the diff map indexes.  Faster than name lookups per frame.
                     } else {
                         Report("ERROR: Morph not found" + Animation_Array[0][item], 0); // Line 318
                         Debug.Break();
                     }
                 }
                 Animation_Array.Add(Line_Array2);
                 
             }
             else
             {
                 for ( item = 0 ; item<Line_Array.length ; item=item+1 )
                 {
                     Line_Array[item] = parseFloat(Line_Array[item]); // Line 329
                     
                     var Found2 : int = FindName( Diff_Maps, [Animation_Array[0][item]] ); // Line 331
                     if ( Found2 != -1)
                     {
                         if (Animation_Array.length == 2 && Diff_Maps[Found2].DM_Multiplier == 0)
                         {
                             Diff_Maps[Found2].DM_Multiplier = parseFloat(Line_Array[item]); // Line 336
                         }
                     }
                 }
                 Animation_Array.Add(Line_Array);
             }
         }
     }
     
     return Animation_Array;
 }
more ▼

asked Oct 02, 2011 at 03:09 PM

rambramdt gravatar image

rambramdt
1 32 23 26

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

All of the error messages you posted are really the same problem appearing in different forms. The problem is that the standard array class doesn't return an array, an animation, a String, a number, or anything really usable. It returns a generic Object. The only thing the program knows about this object that it's a packet of data in Unity. Not terribly useful.

Here's my recomendations:

  • DON'T use the Array() class if you can avoid it. I've never gotten it to work. ever. Use standard "built-in" arrays.
  • Declare the contents of your arrays explicitly.

For example, if you want to work with a 2-d Array of Strings, try this:

     var myArray : String[,] = new String[4,2];
     myArray[0,1] = "A string";
 
     for(var X : int = 0; X < myArray.Length(0); X++)
         for(var Y: int = 0; Y < myArray.Length(1); Y++)
         {
             myArray[X,Y] = "(" + X + ", " + Y + ")";
             Debug.Log(myArray[X,Y]);
         }

If you replace Every instance of the Array() class with a builtInArray[], then your problems should go away.

more ▼

answered Oct 02, 2011 at 09:52 PM

SilverTabby gravatar image

SilverTabby
2.3k 6 12 33

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6276
x3618
x107

asked: Oct 02, 2011 at 03:09 PM

Seen: 2087 times

Last Updated: Oct 02, 2011 at 09:53 PM