Author Topic: return;  (Read 624 times)

Could someone explain to me exactly what return; does? I thought maybe it just went back up to the beginning of the function and went down but the script I am using has it twice, in the same function, so now I'm confused

does the second return; possibly go up to the first return;, and then go down?

From what I remember working with Java it ends the current function without doing anything.

From what I remember working with Java it ends the current function without doing anything.
don't understand :c

In Torque Script it appears to be sort of "ignore me and move on" type of thing.

In Torque Script it appears to be sort of "ignore me and move on" type of thing.
I think I get it


if(%player.Admin $= "1");

return;

The return is triggered if the player has the variable Admin, and it equals 1? , stopping any further functionality after it?

can someone confirm this for me?

return; lets a command end by telling what called it a result. Example:

Code: [Select]
function findClientByName(%name) {
for (%c = 0; %c < ClientGroup.getCount(); %c++) {
%client = ClientGroup.getObject(%c);
if(strStr(%client.name, %name))
return %client;
}
}

It also immediately ends the command without continuing, which is what it is most used for.

I think I get it


if(%player.Admin $= "1");

return;

The return is triggered if the player has the variable Admin, and it equals 1? , stopping any further functionality after it?

can someone confirm this for me?
Since mega had to say some random stuff and didn't answer you, yes that's how it works

I don't see what's wrong with Mega's answer? He explained exactly what return does...


In case he was unclear, return does exit the function... However it can also, in simple terms, transport a value from a function to another function if a value is inserted in front of "return". For example:

Code: [Select]
function lol()
{
     return ":I";
}

function echoLol()
{
     %valueFromLolFunction = lol();
     echo(%valueFromLolFunction);
}
When the "lol" function is called from the "echoLol" function, the value ":I" is returned to the "lol" function and is echoed into the console.
 
« Last Edit: October 27, 2011, 11:36:04 AM by General »

I don't see what's wrong with Mega's answer? He explained exactly what return does...
obviously judging by this topic, siba isn't very advanced into scripting. to a novice, mega's post looks like a bunch of crap shoved together. his example isn't some clear cut thing that will be "oh i see it now!"

return besically will end the function.

function testreturn()
{
     echo("this gets shown");
     return;
     echo("this never gets shown");
}
if you type in testreturn(); the echo will not be shown. this is because the return ended the function.

Stop hurting my feelings, you guys! I was only trying to help!

continue; is also a fun command.