Operator Error.

When I try to use the code below I receive an error on line 16 : “Operator ‘>’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘Object’.” Where is the error since i was unable to find it.

#pragma strict
    var taskPri : Array = Array();
    var taskNam : Array = Array();
    
    var highPri : int;
    
    function NewTask(name : String, priority : int) {
    	taskPri.Push(priority);
    	taskNam.Push(name);
    }
    
    function takeTask() {
    	highPri = 0;
    	for(var x : int = 0; x < taskPri.length; x++) {
    		if(taskPri[x] > taskPri[highPri]) {
    			highPri = x;
    		}
    	}
    }

PS : The code itself is not finished.

The error is at line 15, it’s the only place where you use “>”. And the error states that you try to compare 2 objects using “greater than” (>). Because you define taskPri as just an Array, the compiler sees the elements in it as objects (boxing). You have to be more specific about the types in the array.

You can either try to cast taskPri and taskPri[highPri] to int when you compare them, or just define “taskPri” as “var taskPri : int;”.

taskPri is not defined with the array type. So it stores objects. If you want it to store ints you should define it with the int type.

If you want to store objects you need to cast them to something comparable. This is a bad idea.