function return strings (SOLVED)

Started by JpSoft, Mon 14/07/2008 17:28:36

Previous topic - Next topic

JpSoft

i need create something like this

Code: ags

function whatever()
{
String Resultado;
...
code...
...
return Resultado
}


But i cant find the way. I remember i read something about this some weeks ago, with some one posting about one way to create functions which returns strings , but i was unable to find the topic. Please, any help is very usefull.

Jp

SSH


Code: ags

String whatever()
{
  //...


   return "to sender";
}
12

JpSoft

Quote from: SSH on Mon 14/07/2008 17:30:33

Code: ags

String whatever()
{
  //...


   return "to sender";
}


"to sender" ???  ::) I dont understand it.

if i have this in my global script (my string was previously declared- String MyString; -)

Code: ags
MyString = whatever();


It minds that "to sender" = MyString in this case?

Jp

scotch

The important difference in SSH's example is that the function is declared with the return type "String" rather than "function". Using "function" is the same as using return type "int".

Lt. Smash

#4
whatever type you want to return must be infront of the custom functions name.

so:
Code: ags

//return a String:
String function_name (optional arguments)
{
  ...
  return String; //String can be "Text" or an already declared String datatype
}
//return an int:
int function_name (optional arguments)
{
  ...
  return int;
}
//you can also use float,byte,char

//return a bool:
bool function_name (opt arguments)
{
  ...
  return bool;
}

//in all this functions you have to return a datatype
//but if you don't want to return anything then:
void function_name (optional arguments)
{
  ...
  [return;] //you can write this but you don't need to
}

//the AGS-specific 'function' -function allows you to return ints or nothing (like void)

Khris

Quotethe AGS-specific 'function' -function allows you to return ints or nothing (ie void)
Actually, you can use void if the function isn't supposed to return anything.
Like scotch said, "function" is a substitute for "int".

JpSoft

Very usefull posts. Thanks a lot for the help.

Jp

SMF spam blocked by CleanTalk