Author Topic: Using return; to return info?  (Read 615 times)

I've seen many script use return [something]; in their script. Destiny told me that it returns information but did not go into details. So, I'm wondering what it does.
« Last Edit: June 10, 2011, 08:34:06 PM by Daenth »

echo(returnasdfasoidfjao());

function returnasdfasoidfjao()
{
    return "returnasdfasoidfjao";
}

echo(returnasdfasoidfjao());

function returnasdfasoidfjao()
{
    return "returnasdfasoidfjao";
}
Err, worded my post wrong.
What does it do?

example:


function go()
  {
   %var = myFunction(8);
   echo("var = " @ %var);
  }

function myFunction(%stuff)
  {
   %value = %stuff + 2;
   return %value;
   (or just:    return %stuff + 2; )
  }


then in the console you say:
go();
and get back:
var = 10

-or

echo(myFunction(2));
and get back:
4

example:


function go()
  {
   %var = myFunction(8);
   echo("var = " @ %var);
  }

function myFunction(%stuff)
  {
   %value = %stuff + 2;
   return %value;
   (or just:    return %stuff + 2; )
  }


then in the console you say:
go();
and get back:
var = 10

-or

echo(myFunction(2));
and get back:
4

Huh, but where would you use this?

Huh, but where would you use this?
it depends on your addon, and what your trying to do.

Huh, but where would you use this?
Code: [Select]
function getClientBL_ID(%client)
{
        return %client.bl_id;
}

Basically, it ends a function and gives back a value so that you can use it in if statements or getting things.

for instance, getWord returns the word specified in the string specified.

Huh, but where would you use this?

You need returns in order to do certain things you probably do regularly.

Such as:
findClientByname("Daenth").whatever
findClientByName does a return;

It's like a shortcut.

Would you rather do a for loop in every function you wanna find someone by name or id?

Edit: Also, getRandom(low,high) also uses return. That's how you actually get data out of it.
« Last Edit: June 11, 2011, 12:56:08 AM by Chrono »

I made an illustration based off of what Chrono said.

ya im a artis




The point is, return; is extremely useful and can cut your script's over-complication literally in half

I see now.
Thanks for the help. :)