AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   ArrayList size difference (https://forums.alliedmods.net/showthread.php?t=314916)

_GamerX 03-13-2019 13:46

ArrayList size difference
 
what's the difference?
ArrayList[MAXPLAYERS + 1] PlayerInfo;
vs
ArrayList PlayerInfo[MAXPLAYERS + 1];

both works well

Powerlord 03-13-2019 14:18

Re: ArrayList size difference
 
I'm surprised that ArrayList[MAXPLAYERS + 1] is even allowed as only dynamically sized array are supposed to support brackets after the type according to the docs.

i.e.

PHP Code:

ArrayList[] PlayerInfo = new ArrayList[MaxClients 1]; 

vs.
PHP Code:

ArrayList PlayerInfo[MAXPLAYERS 1]; 

Note that the first would only work inside a method, although you could split it into two parts, like so:

PHP Code:

ArrayList[] PlayerInfo;

//in a method such as OnMapStart
if (PlayerInfo != null)
    
delete PlayerInfo;

PlayerInfo = new ArrayList[MaxClients 1]; 


_GamerX 03-13-2019 14:52

Re: ArrayList size difference
 
I using this

PHP Code:

ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 


impossible_cc 03-15-2019 09:03

Re: ArrayList size difference
 
Quote:

Originally Posted by _GamerX (Post 2643139)
I using this

PHP Code:

ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 


MAXPLAYERS is a constant value, so I do not see any purposes of creating an array with dynamic length.
Just create fixed-length array.
PHP Code:

ArrayList PlayerInfo[MAXPLAYERS 1]; //Global variable

void OnPluginStart()  //Or somewhere else
{
    for(
int i 1<= MaxClientsi++)
    {
        
PlayerInfo[i] = new ArrayList(5);
    }



Fyren 03-19-2019 03:29

Re: ArrayList size difference
 
Quote:

Originally Posted by _GamerX (Post 2643139)
I using this

PHP Code:

ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 



What version of the compiler are you using? This does not compile for me in any of 1.7, 1.8, 1.9, or 1.10.


All times are GMT -4. The time now is 13:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.