13.03.2012, 16:06
You don't need to reference arrays..
Because, In simple words, when you pass an array to a function, the changes occur to the same variable (mem address).
But for Ints, Floats, when you pass to a function, they don't change themselves, they transfer their 'values'.
So, if you want to make changes to their actually values, you need to pass them as references..
Because, In simple words, when you pass an array to a function, the changes occur to the same variable (mem address).
But for Ints, Floats, when you pass to a function, they don't change themselves, they transfer their 'values'.
So, if you want to make changes to their actually values, you need to pass them as references..
pawn Код:
#include <a_samp>
public OnFilterScriptInit()
{
new myINT = 47, Float:myFLT = 2.4751;
DoubleUp_NoRef( myINT, myFLT );
printf("%i %f", myINT, myFLT);
//prints: 47 2.4751
//No changes to our local variables.
DoubleUp( myINT, myFLT );
printf("%i %f", myINT, myFLT);
//prints: 94 4.95
//The values of our local variables has changed.
new myARRAY[32] = "sometext";
DoubleUpArray( myARRAY );
printf("%s", myARRAY);
//prints: sometextsometext
//Even though the Function didn't have referrence arrays
//The local variable has changed it's content.
return true;
}
stock DoubleUp( &INT, &Float:FLT )
{
INT *= 2;
FLT *= 2;
return true;
}
stock DoubleUp_NoRef( INT, Float:FLT )
{
INT *= 2;
FLT *= 2;
return true;
}
stock DoubleUpArray( Array[], size = sizeof Array )
{
strcat(Array, Array, size);
return true;
}

