Quote:
Originally Posted by i8bit
Not saying you guys are wrong, but for me, Starfire's script is the only one I can really understand. Till new to scripting..
I'm still confused on what Return is doing in script..?
|
Here you go [BlueMelon's method...]
PHP Code:
//This is a function for breaking down a large
//number and storing it as individual elements in an array
function numberToArray(temp.n) {
//defining temp.n as an absolute value -- no negatives
temp.n = abs(temp.n);
//setting blank array
temp.digits = {};
//make sure there is a number in temp.n
while(temp.n != 0) {
//if you don't know what % does,
//look up "modulo" on google
//this is inserting each digit into the
//temp.digits array from earlier
temp.digits.insert(0, temp.n % 10);
temp.n = int(temp.n/10);
}
//this returns the array we just set up...
return temp.digits;
}
function onCreated() {
temp.fullnumber = 482;
//here's an example of what return does...
//explained below...
temp.digits = numberToArray(temp.fullnumber);
echo(temp.digits[0]); // 4
echo(temp.digits[1]); // 8
echo(temp.digits[2]); // 2
}
Return basically works like this:
you can set up a function to perform some actions, like sorting these numbers 54925 into an array. well once you've sorted them and put them into the array, you are telling the function to RETURN the data you've gathered or sorted when that function is called
in the example above temp.digits = The Array the function numberToArray(temp.fullnumber) is returning...
Hope that helps a bit...