• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
clear/empty an array
#1
hi!

i wanted to know is there anyway to clear an array with only a few lines? i have player info in this array:

Code:
enum e_playerinfo

{

? ? someInt,

? ? Float:someFloat,

??? someString[144],

}

new playerInfo[MAX_PLAYERS][e_playerinfo];





and i wanted to know how can i clear it in on player disconnect after saving the values in sql, i used to do like this:

Code:
public OnPlayerDisconnect(...)

{



? ? playerInfo[playerid][...] = 0;

? ? playerInfo[playerid][...] = 0.0;

? ? playerInfo[playerid][...] = "";

? ? ...



}

and i had to do this for every variable i add, is there anyway to make this more simple?
  Reply
#2
I think that this should work:



Code:
for(new i; e_playerinfo:i < e_playerinfo; i) { playerInfo[playerid][e_playerinfo:i] = -1; }
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#3
(2021-07-31, 03:53 PM)Pinch Wrote: I think that this should work:

Code:
for(new i; e_playerinfo:i < e_playerinfo; i) { playerInfo[playerid][e_playerinfo:i] = -1; }

so it will work for any data type?
i want it to make the strings "", and ints 0, i think this is not working for every datatype
  Reply
#4
(2021-07-31, 05:09 PM)redex Wrote:
(2021-07-31, 03:53 PM)Pinch Wrote: I think that this should work:



Code:
for(new i; e_playerinfo:i < e_playerinfo; i) { playerInfo[playerid][e_playerinfo:i] = -1; }



so it will work for any data type?

i want it to make the strings "", and ints 0, i think this is not working for every datatype

me neither, but what you can do is manually reset strings, you shouldn't have that much of them anyways?
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#5
This is also a very good way to reset that enum https://github.com/pBlueG/SA-MP-MySQL/bl...e.pwn#L106
Away
  Reply
#6
(2021-07-31, 08:20 PM)Banditul Wrote: This is also a very good way to reset that enum https://github.com/pBlueG/SA-MP-MySQL/bl...e.pwn#L106

Thank you, smart idea
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#7
(2021-07-31, 08:20 PM)Banditul Wrote: This is also a very good way? to reset that enum https://github.com/pBlueG/SA-MP-MySQL/bl...e.pwn#L106



thanks it was really helpful !
  Reply


Forum Jump: