- Home /
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);
Answer by KeithK · Apr 11, 2011 at 08:36 AM
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.
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?
Answer by user-10013 (google) · Apr 16, 2011 at 08:09 AM
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?
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.