functions and arrays - BCE0051

same error with these two.

BCE0051: Operator ‘+’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘Object’.


first case:

Addition (12,33);

function Addition (a,b)
{
var c = a + b;
print (c);
}

second case:

var cod = Array (1,2);
var c = cod[0] + cod[1];

print (c);


Try declaring your types.

#pragma strict

function Awake(){
	Addition (12,33);
	
	var cod = [1,2]; //int array rather than dynamic array of objects
	var c = cod[0] + cod[1];
	print (c);
}

function Addition (a : float, b : float){ //declare types, otherwise they are objects
	var c = a + b;
	print (c);
}

Define the types when declaring variables in functions.

Addition (a : int, b : int)

As for Array, don’t use it. Use built-in arrays (e.g., int[ ]) or List (e.g., List.).

–Eric

now it works but it puts a limit to operations i may want to do

how can i switch after from:
int to string
string to int
int to object
string to object

thanks alot