x


String split script

I'm using this script to draw wireframe. Script read from string file, split coordinate and make vector3 array. In desktop mode all ok, but now in iOS give me error:

Assets/Script/Wireframe.js(33,23): BCE0050: Operator '-' cannot be used with an expression of type 'Object'.

import System.IO;
var Filename : String;

var lineMaterial : Material;
var lineColor : Color;
var lineAlpha : float;
var lineThickness = 1.0;
var line3D = false;

private var line : VectorLine;
private var LinesArray : Vector3[];
private var PointsList : Array;
private var Lines : Array;
private var i : int;

function Start () {
    var sr = new StreamReader(Application.dataPath + "/" + Filename);
    var fileContents = sr.ReadToEnd();
    sr.Close();
    var Points = fileContents.Split(","[0]);

    //PointsList = new Array();
    for (i = 0; i < Points.length; i++){ 
    PointsList.Add(float.Parse(Points[i]));    
  }
    //Lines = new Array();
    for (i = 0; i < PointsList.length / 3; i++){ 
    Lines.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));
} 
    LinesArray = Lines.ToBuiltin(Vector3); 
    line = new VectorLine("Line", LinesArray, lineColor, lineMaterial, lineThickness); 
    VectorManager.useDraw3D = line3D;
    line.joins = Joins.Weld;
    VectorManager.ObjectSetup (gameObject, line, Visibility.Dynamic, Brightness.None);   
}

function LateUpdate (){
    line.vectorObject.renderer.material.color.a = lineAlpha;
}

Somebody help me to correct script?

more ▼

asked Jun 02 '12 at 01:56 PM

benfattino gravatar image

benfattino
160 41 58 61

Can you indicate in your script which line is line "33"?

Jun 02 '12 at 02:22 PM kolban
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The "Array" type is an untyped collection of arbitrary objects, so although you put floats in, the compiler doesn't know that when you're accessing the elements again.

I'm not a Master of UnityScript, since I always use C#, so I don't know what the best alternative is. But your problem should be solved by replacing every "PointsList[..." in your line starting with "Lines.Add" with "(float)PointsList[...", or maybe "float(PointsList[...])". In C# you could do "PointsList[...] as float", but I don't know if that's available in UnityScript.

more ▼

answered Jun 02 '12 at 02:25 PM

Wolfram gravatar image

Wolfram
9k 8 20 52

Lines.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));

Jun 02 '12 at 10:12 PM benfattino

The best alternative is a generic List; the JS Array class should not be used even in JS.

Jun 02 '12 at 10:36 PM Eric5h5
(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:

x3325
x418
x80

asked: Jun 02 '12 at 01:56 PM

Seen: 563 times

Last Updated: Jun 02 '12 at 10:36 PM