real quick question about using functions in array delaclarations.

 

Ran into a problem with an array.

datetime arrobjt[2]={ObjectGet(id,OBJPROP_TIME2),ObjectGet(id,OBJPROP_TIME2),ObjectGet(id,,OBJPROP_TIME3)};


Thought this would work but I keep getting a variable expected "OBJPROP_TIME1" is it possible to use a function in this situation?

Am I missing something.. Purely for learning. I know I could load the array with a loop etc.

Thanks for the help and answers.

 

Did you read the code you posted ?

Why the double ,, ?

ObjectGet(id  ,,  OBJPROP_TIME3)
 
fractalcurve:


Ran into a problem with an array.

datetime arrobjt[2]={ObjectGet(id,OBJPROP_TIME2),ObjectGet(id,OBJPROP_TIME2),ObjectGet(id,,OBJPROP_TIME3)};


Thought this would work but I keep getting a variable expected "OBJPROP_TIME1" is it possible to use a function in this situation?

Am I missing something.. Purely for learning. I know I could load the array with a loop etc.

Thanks for the help and answers.

Well according to the manual you don't have to initialize from a constant for local variables, so it seems as though it should work. Clearly it doesn't.

It is not ideal to initialize a two element array with 3 elements!

 
type arr[size] = { item1, item2, ...};
Will not work, the items MUST be constants.
datetime arrobjt[3];
arrobjt[0]=ObjectGet(id,OBJPROP_TIME2);
arrobjt[1]=ObjectGet(id,OBJPROP_TIME2);
arrobjt[2]=ObjectGet(id,OBJPROP_TIME3);
Why are the first two elements initialized to the SAME value?
 

Thanks for all of the replies.. Sorry I did not reply earlier. I did not realize that the elements must be constants.

This was very helpful!


.

Reason: