Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JpSoft on Mon 14/07/2008 17:28:36

Title: function return strings (SOLVED)
Post by: JpSoft on Mon 14/07/2008 17:28:36
i need create something like this


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
Title: Re: function return strings
Post by: SSH on Mon 14/07/2008 17:30:33


String whatever()
{
  //...


   return "to sender";
}
Title: Re: function return strings
Post by: JpSoft on Mon 14/07/2008 17:57:05
Quote from: SSH on Mon 14/07/2008 17:30:33


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; -)

MyString = whatever();

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

Jp
Title: Re: function return strings
Post by: scotch on Mon 14/07/2008 18:02:44
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".
Title: Re: function return strings
Post by: Lt. Smash on Tue 15/07/2008 14:27:08
whatever type you want to return must be infront of the custom functions name.

so:

//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)
Title: Re: function return strings
Post by: Khris on Tue 15/07/2008 16:50:19
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".
Title: Re: function return strings
Post by: JpSoft on Tue 15/07/2008 19:00:40
Very usefull posts. Thanks a lot for the help.

Jp