Raised This Month: $51 Target: $400
 12% 

Solved No entries inside an array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-13-2018 , 04:54   No entries inside an array
Reply With Quote #1

How do I check whether there's no entries inside a cellarray? I need to show the player an error log if the array is empty.

Is this correct?
PHP Code:
    new iArraySize ArraySizeg_aCustomSpawnPoints );
    
    if( ! 
iArraySize )
    {
        
log_amx"[CSBR] No Custom Origins Found" );
        return 
0;
    } 
If we use ArrayPushArray, does ArraySize go from -1 to 0 or from 0 to 1?
__________________

Last edited by edon1337; 09-13-2018 at 15:27.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-13-2018 , 05:36   Re: No entries inside an array
Reply With Quote #2

Why not just try ArraySize on a newly created array?
Also did you ever see an array with -1 elements, in any language? Does it make sense to you?
__________________

Last edited by klippy; 09-13-2018 at 05:36.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-13-2018 , 05:39   Re: No entries inside an array
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
Why not just try ArraySize on a newly created array?
Also did you ever see an array with -1 elements, in any language? Does it make sense to you?
Well, why do we loop from 0 to ArraySize-1 if 0 is the starting entry which is blank then?
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-13-2018 , 05:46   Re: No entries inside an array
Reply With Quote #4

Quote:
Originally Posted by edon1337 View Post
Well, why do we loop from 0 to ArraySize-1 if 0 is the starting entry which is blank then?
In the ordinary array loop
Code:
new const size = ArraySize(myArray);
for(new i = 0; i < size; i++) {

}
if size is 0 (empty) no iterations will occur. If size is 1, one iteration will occur. I'm not sure I understand your logic.
__________________

Last edited by klippy; 09-13-2018 at 05:47.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-13-2018 , 06:10   Re: No entries inside an array
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
In the ordinary array loop
Code:
new const size = ArraySize(myArray);
for(new i = 0; i < size; i++) {

}
if size is 0 (empty) no iterations will occur. If size is 1, one iteration will occur. I'm not sure I understand your logic.
What I'm trying to say is:

PHP Code:
new iArraySize ArraySizemyArray ), eDataData ];

for( new 
0iArraySizei++ )
{
    
ArrayGetArraymyArrayieData );

Why would we even check the first item (0) if we know that it is blank? That's why I asked whether array size starts from -1.
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-13-2018 , 06:51   Re: No entries inside an array
Reply With Quote #6

Why do you assume first item is always blank? An ArraySize of 0 simply means the array has no item, it is empty. If you have an item it will be at slot 0 and the size fo array is 1.
__________________

Last edited by HamletEagle; 09-13-2018 at 06:53.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-13-2018 , 07:02   Re: No entries inside an array
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
Why do you assume first item is always blank? An ArraySize of 0 simply means the array has no item, it is empty. If you have an item it will be at slot 0 and the size fo array is 1.
Oh so, ArraySize == 0 means that the Array is empty and has no entries, and ArraySize == 1 means there's just one entry and the array isn't empty?
__________________
edon1337 is offline
Garey
Member
Join Date: Feb 2008
Location: Russian Federation
Old 09-13-2018 , 07:14   Re: No entries inside an array
Reply With Quote #8

Yes, first element of array have index 0, and size of array is 1, so in loops you need to get arraysize-1 if using with ArrayGet* and <=
__________________
Sorry for my bad english

Last edited by Garey; 09-13-2018 at 07:15.
Garey is offline
Send a message via ICQ to Garey
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-13-2018 , 09:19   Re: No entries inside an array
Reply With Quote #9

So, why is log_amx being sent when my array has 1 entry?

PHP Code:
public OnNewRound( )
{
    if( 
GetRandomZoneOriging_fZoneOrigin ) == -)
    {
        
log_amx"[CSBR] No Zone Origins Found" );
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

GetRandomZoneOriginFloat:fOutput] )
{
    new 
iArraySize ArraySizeg_aZoneOrigins );

    if( ! 
iArraySize )
    return -
1;
    
    new 
eDataZoneData ];
    
    new 
iEntry random_num0iArraySize );
    
ArrayGetArrayg_aZoneOriginsiEntryeData );
    
    for( new 
03i++ )
    {
        
fOutput] = eDataZoneOrigins ][ ];
    }
    return 
1;

__________________

Last edited by edon1337; 09-13-2018 at 09:20.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-13-2018 , 09:47   Re: No entries inside an array
Reply With Quote #10

That's not nearly enough code for someone to tell, obviously your g_aZoneOrigins is empty.
__________________
klippy 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:53.


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