function breakTest()
{
for(%a = 0; %a < 100; %a++)
{
if(%a == 20)
break;
echo("Loop is at:" SPC %a);
}
}
Will echo 20 times. On the 21st time, when %a is equal to 20, it will hit the if condition and break.
function sum(%a, %b)
{
return (%a + %b);
}
This is the example typically used, but since just doing (%a + %b) will return the exact same result without the CPU overhead of a function call, it's a pointless impractical example.
Semantically, "get" functions are attached to objects to reduce redundant code. If you find yourself repeating the same 5 lines of code over and over again to get something from a related object, chances are you will want to make a "get" function. That way, if something changes later on, you won't be replacing tons of code.
For example, if we want to get the full player title, with clan tags, we'd need to do this:
%fullTitle = %client.clanPrefix @ %client.getPlayerName() @ %client.clanSuffix;
If you do this:
function GameConnection::getFullTitle(%client)
{
return %client.clanPrefix @ %client.getPlayerName() @ %client.clanSuffix;
}
Elsewhere, you can just do this:
%fullTitle = %client.getFullTitle();