I have tested the first two (index and add) but not delete. Seems like it should work though.
My question on the delete function is how will having an empty entry in the array affect things? Will GetArraySize still return a valid value if you had an array with 10 names in it put deleted the first 2?
Hopefully others find these useful.
[nwscript]
///////////////////////////array functions///////////////////////
int GetStringArrayIndex(string [] sHaystack, string sNeedle)
{
int iSize=GetArraySize(sHaystack);
if(iSize==0) return -1;
int iIndex;
for ( iIndex = 0; iIndex < iSize; iIndex++ )
{
if(sHaystack[iIndex]==sNeedle)return iIndex;
}
return -1;
}
////////////////////
void AddStringToArray(string [] sArray, string sAdd)
{
int iPosition=GetArraySize(sArray);
if(GetStringArrayIndex(sArray,sAdd)==-1) //only add unique entries
sArray[iPosition]=sAdd;
}
////////////////////
void DeleteStringFromArray(string [] sArray, string sDelete)
{
int iDelete=GetStringArrayIndex(sArray,sDelete);
if(iDelete>=0)//only delete if it exists in array
sArray[iDelete]="";
}
[/nwscript]
Modifié par georage, 12 décembre 2009 - 01:14 .





Retour en haut






