x


Custom Sort class array error if i use #pragma

Hy! I use this sort. Work perfect, but i use #pragma strict, #pragma implicit, #pragma downcast = console error 'Time' is not a member of 'Object'. How to fix this?

private var FinishList : Array = new Array();
class Info {
var Name : String;
var Time : float;
}

function AddFinish(name : String , time : float){   
    var newinfo : Info = new Info();
    newinfo.Name = name;
    newinfo.Time = time;    
    FinishList.Add(newinfo);
}

  function SortTime(thisObject,thatObject) {  //id rendezs nvekv sorrendbe
    if (thisObject.Time > thatObject.Time)
    {
        return 1;
    }
    else if (thisObject.Time < thatObject.Time)
    {
        return -1;
    }
    return 0;
  }

FinishList.sort(SortTime);
more ▼

asked Apr 11 '11 at 08:16 AM

user-10013 (google) gravatar image

user-10013 (google)
5 2 2 7

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

2 answers: sort voted first

You need to specify your object types if you use strict. Or else they will just be treated as Objects. So in SortTime() you need to give those parameters types, like you have in AddFinish().

function SortTime(thisObject : <SomeType>, thatObject : <SomeType>)

Obviously without the angle brackets.

more ▼

answered Apr 11 '11 at 08:36 AM

KeithK gravatar image

KeithK
862 2 3 13

Thanks the help!

Apr 11 '11 at 08:54 AM user-10013 (google)

Can i help another problem? How sort Info.Name?

function SortTime(thisObject : Info ,thatObject : Info ) {
if (thisObject.Name > thatObject.Name) { return 1; } else if (thisObject.Name < thatObject.Name) { return -1; } return 0; }

Dont work error: Operator '>' cannot be used with a left hand side of type 'String' and a right hand side of type 'String'.

I tried it too:

function SortTime(thisObject : Info ,thatObject : Info ) {
return thisObject.Name - thatObject.Name ; }

but does not work. How fix this?

Apr 16 '11 at 08:28 AM user-10013 (google)
(comments are locked)
10|3000 characters needed characters left

Can i help another problem?

How sort Info.Name?

I change SortTime function:

  function SortTime(thisObject : Info ,thatObject : Info ) {  
    if (thisObject.Name > thatObject.Name)
    {
        return 1;
    }
    else if (thisObject.Name < thatObject.Name)
    {
        return -1;
    }
    return 0;
  }

Dont work error: Operator '>' cannot be used with a left hand side of type 'String' and a right hand side of type 'String'.

I tried it too:

  function SortTime(thisObject : Info ,thatObject : Info ) {  
      return thisObject.Name - thatObject.Name ;
  }

but does not work. How fix this?

more ▼

answered Apr 16 '11 at 08:09 AM

user-10013 (google) gravatar image

user-10013 (google)
5 2 2 7

You should post this as a new question. Not many other people will see this because this thread is marked as answered. Also, you should just never ask a question in an answer post.

Apr 17 '11 at 07:01 AM KeithK

Ok, Sorry and thanks!

Apr 17 '11 at 11:58 AM user-10013 (google)
(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:

x1363
x339
x59
x32

asked: Apr 11 '11 at 08:16 AM

Seen: 1163 times

Last Updated: Apr 11 '11 at 08:16 AM