Is it possible to return an int from a datetime function?

 

Is it possible to return an int from a datetime function?


datetime foo(int size) {

size = 2;
return size;
}
 

if its not possible how can i copy values from one function to another, is this a right way?

datetime foo(int size) {

int size = 2;
Size(size)
}

int Size(int value) {
return value;
}

void OnTick() { Print(Size()) }
 
Arpit T: Is it possible to return an int from a datetime function?

Of course you can.

datetime foo(int size) {
size = 2; // Thu Jan 01 1970 00:00:02 GMT+0000
return datetime(size);
}

Why you would want to is a different question.
     How To Ask Questions The Smart Way. (2004)
          The XY Problem

 
William Roeder #:

Of course you can.

Why you would want to is a different question.
     How To Ask Questions The Smart Way. (2004)
          The XY Problem

i dont want to return datetime(size)

I only want to return size

 
Arpit T #: i dont want to return datetime(size) I only want to return size

Then don't return a datetime datatype. return an int datatype.

int foo(int size)
{
   size = 2;
   return size;
};

A function can only return one datatype, but you can typecast it as William pointed out in his post.

 
Fernando Carreiro #:

Then don't return a datetime datatype. return an int datatype.

A function can only return one datatype, but you can typecast it as William pointed out in his post.

ok, thanks if i have some int value in datetime function

then how can i copy that int value from datetime function to int function?

 

Code:

int(func());

// ---------
datetime func()
{
datetime time=0;
... // (time is calculated here)
return(time);
}
 
Arpit T #: ok, thanks if i have some int value in datetime function then how can i copy that int value from datetime function to int function?

Your question is not making much sense. Provide a more realistic example of the code you wish to use and explain in more detail.

 
Fernando Carreiro #:

Your question is not making much sense. Provide a more realistic example of the code you wish to use and explain in more detail.

datetime DataDate() {
datetime T = TimeGMT();
int a = 6; // this value to be exported to DataInt() function

return T;
}

Print(DataDate()); // Prints Time GMT

//now

int DataInt(int a ) {
return a;
}

Print(Data(2)); // Returns int value 2
// Here i want to have value of 2 to be copied from inside of DataDate() function and output to be 6 because a=6 is there inside DataDate() function
 
Arpit T #:

Is this what you want?

datetime DataDate( int &var )
{
   datetime T = TimeGMT();
   int a = 6; // this value to be exported to DataInt() function

   var = a;
   return T;
};

void someotherfunction( void )
{
   int myVar;
   Print( DataDate( myVar ) ); // Prints Time GMT
   Print( myVar ) ); // Returns int value 6
};

You can also use globally scoped variables ...

int myVar;

datetime DataDate( void )
{
   datetime T = TimeGMT();
   int a = 6; // this value to be exported to DataInt() function

   myVar = a;
   return T;
};

void someotherfunction( void )
{
   Print( DataDate() ); // Prints Time GMT
   Print( myVar ); // Returns int value 6
};
 
Fernando Carreiro #:

Is this what you want?

You can also use globally scoped variables ...

thanks using global variable is great idea

Reason: