If you're assuming GetIntArrayIndex() returns a 0 based index like every other functions and structure in there, think again. (pastie)
int[] aiphaetest;
aiphaetest[0] = 541;
aiphaetest[1] = 582;
aiphaetest[2] = 742;
aiphaetest[3] = 562;
aiphaetest[4] = 589;
Phae_print(IntToString(GetIntArrayIndex(aiphaetest, 562))); return;[/code]
This code displays "4" , meaning a match at [0] will be returned as index 1, etc.
That does make sense when looking at the function source in core_h, however : (pastie)
// return the index of the first occurence of an integer in an integer array
int GetIntArrayIndex (int[] arArray, int nItem) {
int nSize = GetArraySize(arArray);
int bFound;
int i;
for (i = 0; i < nSize && !bFound; i++) {
bFound = (arArray[i] == nItem);
}
return (bFound ? i : -1) ;
}Put like that, the for statement will increment the variable i before checking if the conditional is false. That's plainly what for does for a living. Duh.
The same concept error is found in GetObjectArrayIndex() so that one will behave the same.
// Edit :
Added some pasties, code coloring here would be nice. Nii~iice. I tell you.
Modifié par Phaenan, 27 novembre 2009 - 12:45 .





Retour en haut






