Author Topic: Very simple kill command, need help  (Read 3047 times)

it's so you can send a bit of information back out of the function

for example (poor example)

function getNumber1()
{
return 1;
}

function doMaths(%addme)
{
echo(getNumber1() + %addme);
}


then you go in your console and do doMaths(4); and it tells you "5"

in this instance getNumber1() is usable in exactly the same way as the number 1

now think what happens when you use variables and math in the getNumber1() function!

all of a sudden you can do math and stuff outside of your main function, and use your calculations elsewhere! it's a good deal.

it's so you can send a bit of information back out of the function

for example (poor example)

function getNumber1()
{
return 1;
}

function doMaths(%addme)
{
echo(getNumber1() + %addme);
}


then you go in your console and do doMaths(4); and it tells you "5"

in this instance getNumber1() is usable in exactly the same way as the number 1

now think what happens when you use variables and math in the getNumber1() function!

all of a sudden you can do math and stuff outside of your main function, and use your calculations elsewhere! it's a good deal.

i see, thanks :) however i still dont understand why they were used in my short piece of script, when it was all inside one function and didnt need to be used outside of the function

i see, thanks :) however i still dont understand why they were used in my short piece of script, when it was all inside one function and didnt need to be used outside of the function
Return also ends the function and goes on to the rest of your code. For example, if something is passed into the function that can't be used, you can make the function detect that and end it before it tries to do anything with the input.
« Last Edit: September 23, 2012, 03:07:11 PM by Scars75 »

Return also ends the function and goes on to the rest of your code, so if the user inputs something that can't be used, you can make the function detect that and end it before it tries to do anything with the input.
function serverCmdAmIAdmin(%client)
{
if(%client.isAdmin == false)
{
messageClient(%client, '', "No.");
return;
} //Nothing is done after this line if they aren't admin because of the return, so everything after it basically is read as "They passed the 'are you /not/ admin?' test, therefore they must be admin!"
messageClient(%client, '', "Yes!");
}

function serverCmdAmIAdmin(%client)
{
if(%client.isAdmin == false)
{
messageClient(%client, '', "No.");
return;
} //Nothing is done after this line if they aren't admin because of the return, so everything after it basically is read as "They passed the 'are you /not/ admin?' test, therefore they must be admin!"
messageClient(%client, '', "Yes!");
}
For example
the forum should notify you when the post you're quoting is changed

the forum should notify you when the post you're quoting is changed
i was providing a working example of the same thought

locking topic
I don't know if you crossed that out because you unlocked or, or because you remembered you shouldn't. But know that you shouldn't lock threads in coding help just because the question has been answered. Someone may have a better solution or see an issue with the "solution" but they can't give it to you if it's locked.

and there is a syntax error somewhere, but i cant find it
I don't know how much you tried, but the error report gives you a line number (most text editors allow your to press ctrl+G to go to a certain line) and a general location of the error, you should practice finding and fixing the error yourself.

Also, I don't know what you have now, but in the code in this post, you can get rid of either the return or the else

he unlocked because i told him to

I don't know if you crossed that out because you unlocked or, or because you remembered you shouldn't. But know that you shouldn't lock threads in coding help just because the question has been answered. Someone may have a better solution or see an issue with the "solution" but they can't give it to you if it's locked.
I don't know how much you tried, but the error report gives you a line number (most text editors allow your to press ctrl+G to go to a certain line) and a general location of the error, you should practice finding and fixing the error yourself.

Also, I don't know what you have now, but in the code in this post, you can get rid of either the return or the else

okay, and with the syntax error, it was a syntax error i was unfamiliar with, but yes i did look thouroughly through the script to look out for one, and the syntax error i did was one i didnt know about

okay, and with the syntax error, it was a syntax error i was unfamiliar with, but yes i did look thouroughly through the script to look out for one, and the syntax error i did was one i didnt know about
Alright, that's fine, but if it happens with a larger script, include the error report (at least the line number) so people have a more specific area to look