A way to reference array - T0pAz - 13.03.2012
Is there a way to reference an array?
Re: A way to reference array -
TTJJ - 13.03.2012
Hi T0pAz,
Reference an array, I assume you mean retrieve a variable from an array?
Cheers,
TJ
Re: A way to reference array - T0pAz - 13.03.2012
Quote:
Originally Posted by TTJJ
Hi T0pAz,
Reference an array, I assume you mean retrieve a variable from an array?
Cheers,
TJ
|
I want to do something like this.
Re: A way to reference array -
TTJJ - 13.03.2012
Hi T0pAz,
Ok, there is no need to use the & symbol in this instance. So if you want to pass an array to a function, the following would be a good example:
pawn Код:
public OnGameModeInit()
{
new arr[10];
ProcessMyArray(arr);
}
public ProcessMyArr(array[])
{
//Do something...
}
I believe that is what you are looking for?
Cheers,
TJ
Re: A way to reference array - T0pAz - 13.03.2012
Quote:
Originally Posted by TTJJ
Hi T0pAz,
Ok, there is no need to use the & symbol in this instance. So if you want to pass an array to a function, the following would be a good example:
pawn Код:
public OnGameModeInit() {
new arr[10]; ProcessMyArray(arr);
}
public ProcessMyArr(array[]) {
//Do something...
}
I believe that is what you are looking for?
Cheers,
TJ
|
But I tend to not use format.
Re: A way to reference array -
eesh - 13.03.2012
arrays are more like strings in pawn so do it like string.
example:
str[8]="hello";
str[3] would be l.
so if hello[12] is an array try
Re: A way to reference array - T0pAz - 13.03.2012
Quote:
Originally Posted by eesh
arrays are more like strings in pawn so do it like string.
example:
str[8]="hello";
str[3] would be l.
so if hello[12] is an array try
|
Arrays cannot be returned.
Re: A way to reference array -
TTJJ - 13.03.2012
Hi Again,
The way I return formatted strings is the following:
pawn Код:
public doIt(str[],length)
{
new stuff = 1;
return format(str,length,"%d",stuff);
}
public OnPlayerConnect(playerid)
{
new str[32];
doIt(str,32);
}
That may be of assistance..
Cheers,
TJ
Re: A way to reference array -
iPLEOMAX - 13.03.2012
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;
}
Re: A way to reference array - T0pAz - 13.03.2012
Quote:
Originally Posted by iPLEOMAX
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( myINT, myFLT ); printf("%i %f", myINT, myFLT); new myARRAY[32] = "sometext"; DoubleUpArray( myARRAY ); printf("%s", myARRAY); return true; }
stock DoubleUp( &INT, &Float:FLT ) { INT *= 2; FLT *= 2; return true; }
stock DoubleUpArray( Array[], size = sizeof Array ) { strcat(Array, Array, size); return true; }
|
Thanks man!