Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot General Programming clear/empty an array

 
  • 0 Vote(s) - 0 Average
clear/empty an array
redex
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: May 2021
Reputation: 0
Location: Germany
#1
2021-07-31, 01:21 PM
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?
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#2
2021-07-31, 03:53 PM
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.
redex
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: May 2021
Reputation: 0
Location: Germany
#3
2021-07-31, 05:09 PM (This post was last modified: 2021-07-31, 05:23 PM by redex.)
(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
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#4
2021-07-31, 07:33 PM
(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.
Banditul Away

Burgershot Member
Posts: 38
Threads: 0
Joined: Apr 2019
Reputation: 2
#5
2021-07-31, 08:20 PM
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
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#6
2021-08-01, 12:22 PM
(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
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.
redex
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: May 2021
Reputation: 0
Location: Germany
#7
2021-08-02, 05:29 PM
(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 !
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode