Burgershot
clear/empty an array - Printable Version

+- Burgershot (https://www.burgershot.gg)
+-- Forum: General (https://www.burgershot.gg/forumdisplay.php?fid=19)
+--- Forum: Programming (https://www.burgershot.gg/forumdisplay.php?fid=56)
+--- Thread: clear/empty an array (/showthread.php?tid=2200)



clear/empty an array - redex - 2021-07-31

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?


RE: clear/empty an array - Pinch - 2021-07-31

I think that this should work:

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



RE: clear/empty an array - redex - 2021-07-31

(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


RE: clear/empty an array - Pinch - 2021-07-31

(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?


RE: clear/empty an array - Banditul - 2021-07-31

This is also a very good way to reset that enum https://github.com/pBlueG/SA-MP-MySQL/blob/master/example_scripts/login_system-cache.pwn#L106


RE: clear/empty an array - Pinch - 2021-08-01

(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/blob/master/example_scripts/login_system-cache.pwn#L106
Thank you, smart idea


RE: clear/empty an array - redex - 2021-08-02

(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/blob/master/example_scripts/login_system-cache.pwn#L106

thanks it was really helpful !