Alert Values from Function with MLQ4

 

How can I alert values from an array created by a function?  


Alert(XYZ[1]); // Should alert 4.56

double XYZ(string y, int z)  {
   double x[3];
   x[0] = 0.123;
   x[1] = 4.56;
   x[2] = 7.89;
   return(x);
}

 
hknight:

How can I alert values from an array created by a function?  

You can't return an array from a function.

Your function takes 2 parameters you are only calling it with one. 

 
 double zzz = XYZ("Q", 1);
 Alert("zzz: ", zzz[1] );

 

That does not work either.

So there is no good way for a function to return an array?  

 
hknight:

 That does not work either.

So there is no good way for a function to return an array?  

Of course it doesn't work . . .

RaptorUK:

You can't return an array from a function.

You aren't trying to return an array though,  are you ?  aren't you just trying to return the element as specified in the value passed to the function ?  I'm guessing because you haven't said what you are trying to achieve.
 
hknight: How can I alert values from an array created by a function?  

 Your code - Not passing arguments, trying to return an array.
Try this.
Alert(XYZ[1]); // Should alert 4.56

double XYZ(string y, int z)  {
   double x[3];
   x[0] = 0.123;
   x[1] = 4.56;
   x[2] = 7.89;
   return(x);
}
double arr[3]; XYZ(arr, "a", 0);
Alert(arr[1]); // Should alert 4.56

void XYZ(double& x[], string y, int z){ // x by reference
// double x[3];
   x[0] = 0.123;
   x[1] = 4.56;
   x[2] = 7.89;
   return; //(x);
}
 
Perfect, thanks!