Raised This Month: $ Target: $400
 0% 

Check if 2d array contains no data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-04-2007 , 13:38   Check if 2d array contains no data
Reply With Quote #1

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?     } }
hlstriker is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-04-2007 , 13:44   Re: Check if 2d array contains no data
Reply With Quote #2

Try this...to compare strings use equal() or contain()
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
__________________
regalis is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 06-05-2007 , 15:28   Re: Check if 2d array contains no data
Reply With Quote #3

I believe you can just do this:
Code:
if(!array[0][0]) { }
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-05-2007 , 16:03   Re: Check if 2d array contains no data
Reply With Quote #4

@ v3x: that will work only for array[0]
_Master_ is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-06-2007 , 10:52   Re: Check if 2d array contains no data
Reply With Quote #5

@_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?
     
}

stupok is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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