return; // not exactly sure what this does, but it might just be an end statement???
The
return; statement stops the code from running, whilst allowing the function to return data.
When you call a statement such as this:
%target = findclientbyname(%name);What you first need to know is that findclientbyname itself, is a function. If I were to guess what the code looked like, it would look like this:
function findClientByName(%name)
{
for(%a=0;%a<ClientGroup.getCount();%a++)
{
%b = ClientGroup.getObject(%a);
if(strStr(%b.name, %name) >= 0)
return %b;
}
return false;
}
Disclaimer: I'm not sure if findClientByName is at all written in torque script - it might be written in the c++ side of the engine.When you use return, you can also attach any/some sort of data (usually boolean) to return with it. Here are some samples of returning data:
return; // returns nothing, used to terminate the current code being ran.
return true;
return false;
return 100-50;
return %a-%b+c;
return %string;
return %word1 SPC %word2 SPC %word3;
return strLen("THIS IS A STRING");
Now back to the
%target = findclientbyname(%name); line. %target is a variable that will now hold the value of what the function (findClientByName) had returned. In this case, it's the client object that the player is connected to.
The return statement is widely used upon all (I think) programming. In torque script you can use it to your own use like:
function minus(%a, %b)
{
return %a - %b;
}
function main()
{
%blah = 9;
%what = 5;
%result = minus(%blah, %what);
echo(%result);
// '4' is what should be echo'd in console.
}
And a little further advanced, you can use return in a recursive manner to create another kind of loop:
function getOneHundred(%count)
{
if(getRandom(0, 100) != 100)
return %count;
else
return getOneHundred(%count+1);
}
This will run (infinitely) until getRandom(min, max); generates '100' as a random number. In the event that it doesn't generate '100', it will call itself again to generate it (thus again.. infinitely). Also, while it's doing that, I'm making it pass an argument of %count to keep track of how many times it is calling itself. That way I can see how many attempts it needs for it to roll '100'.
I probably forgot to cover some other stuff. If anyone else has anything to add on, feel free to do so.