A way to reference array
#9

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..

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;
}
Reply


Messages In This Thread
A way to reference array - by T0pAz - 13.03.2012, 14:43
Re: A way to reference array - by TTJJ - 13.03.2012, 14:44
Re: A way to reference array - by T0pAz - 13.03.2012, 14:48
Re: A way to reference array - by TTJJ - 13.03.2012, 14:50
Re: A way to reference array - by T0pAz - 13.03.2012, 14:52
Re: A way to reference array - by eesh - 13.03.2012, 14:57
Re: A way to reference array - by T0pAz - 13.03.2012, 15:06
Re: A way to reference array - by TTJJ - 13.03.2012, 15:10
Re: A way to reference array - by iPLEOMAX - 13.03.2012, 16:06
Re: A way to reference array - by T0pAz - 13.03.2012, 16:13

Forum Jump:


Users browsing this thread: 1 Guest(s)