AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if 2d array contains no data (https://forums.alliedmods.net/showthread.php?t=56014)

hlstriker 06-04-2007 13:38

Check if 2d array contains no data
 
How can I check if a 2d array has data stored in the first dimension or not. I thought checking if it is 0, but that gives me a compile error "array must be indexed (variable "array2d")".

Example:
Code:
new array2d[33][128]; for(new i=0; i<32; i++) {     if(array2d[i] != 0)     {         // First dimension has no data?     } }

regalis 06-04-2007 13:44

Re: Check if 2d array contains no data
 
Try this...to compare strings use equal() or contain() :wink:
Code:

new array2d[33][128];

for(new i=0; i<32; i++)
{
    if(equal(array2d[i][], ""))
    {
        // First dimension has no data?
    }
}

or this would also work i think..
Code:

new array2d[33][128];

for(new i=0; i<32; i++)
{
    if(array2d[i][0] == 0))
    {
        // First dimension has no data?
    }
}

greetz regalis

v3x 06-05-2007 15:28

Re: Check if 2d array contains no data
 
I believe you can just do this:
Code:
if(!array[0][0]) { }

_Master_ 06-05-2007 16:03

Re: Check if 2d array contains no data
 
@ v3x: that will work only for array[0] :wink:

stupok 06-06-2007 10:52

Re: Check if 2d array contains no data
 
@_Master_
I think v3x is saying this:

PHP Code:

new array2d[33][128];
for(new 
i=0i<32i++)
{     
     if(!
array2d[i][0])
     {
          
// First dimension has no data?
     
}




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

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