SA-MP Forums Archive
"destroying" an array row. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: "destroying" an array row. (/showthread.php?tid=418353)



"destroying" an array row. - JamesS - 24.02.2013

Well, I'll try to explain myself properly. I'm asking if it's possible to :

Lets say I got this array. (example: i'm not really doing this).

new PlayerStuff[MAX_PLAYERS]

PlayerStuff[0] = "Money";
PlayerStuff[1] = "Weapons";
PlayerStuff[3] = "Drugs";
PlayerStuff[4] = "Other";
etc...

Now, I want for example "weapons" removed, but I want this as result :

PlayerStuff[0] = "Money";
PlayerStuff[1] = "Drugs";
PlayerStuff[3] = "Other";
etc..

So, I actually want to delete the content of the array-row, and reduce the index of the follow element rows by 1.

Well if this is possible (For all the stuff in my array, there is a txt file, I need that txt file removed (dini_remove) but, besides that, i need the following txt names also reduced by 1.) names of the txt files are just like 1,2,3,4 etc.

Sorry, I couldn't really explain myself properly, I hope you get the idea. Thanks for any feedback.


Re: "destroying" an array row. - Vince - 24.02.2013

This is not possible in Pawn. At least not in an easy way. Furthermore, renaming a file means copying all contents of the old file to a new file with the designated name and deleting the old file afterwards.


Re: "destroying" an array row. - JamesS - 24.02.2013

Quote:
Originally Posted by Vince
View Post
This is not possible in Pawn. At least not in an easy way. Furthermore, renaming a file means copying all contents of the old file to a new file with the designated name and deleting the old file afterwards.
And whats the not simple way then?


Re: "destroying" an array row. - Misiur - 24.02.2013

1. By hand
2. Delete element, loop through all remaining elements, change their index and rename their filename to corresponding index.


Re: "destroying" an array row. - Vince - 24.02.2013

Means you 'll need an algorithm to copy the contents of index x to index x-1. However, you cannot actually decrease an array's total size, since it's set statically at compile time.


Re: "destroying" an array row. - JamesS - 24.02.2013

So, basicly, this is impossible?


Re: "destroying" an array row. - LarzI - 24.02.2013

Quote:
Originally Posted by JamesS
View Post
So, basicly, this is impossible?
Quote:
Originally Posted by Vince
View Post
This is not possible in Pawn.
You tell me.


Re: "destroying" an array row. - JamesS - 24.02.2013

Quote:
Originally Posted by LarzI
View Post
You tell me.
Quote:
Originally Posted by Vince
View Post
At least not in an easy way.
Uhhh..


Re: "destroying" an array row. - Misiur - 24.02.2013

pawn Code:
new Sacrifice[4][4] = {
    "Yay",
    "Op",
    "Is",
    "Yay"
};

//Blargh. Let's kill OP
new target = 1;
Sacrifice[target][0] = EOS;
for(new i = target + 1; i < sizeof Sacrifice; ++i) {
    if(Sacrifice[i][0] == EOS) continue;
    strcat(Sacrifice[i-1], Sacrifice[i]);
    Sacrifice[i][0] = EOS;
}
Add additional file renaming, and done


Re: "destroying" an array row. - AndreT - 24.02.2013

You can use the CSTL plugin for example - it provides you with vectors.