Raised This Month: $ Target: $400
 0% 

Array dimensions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DavidLin
Member
Join Date: Jan 2016
Old 01-09-2016 , 18:18   Array dimensions
Reply With Quote #1

I have this code to add a const array to defined array but it shows that dimensions don't match

PHP Code:
new const ZOMBIE_PAIN[ ][ ]     = { "s/zombie/pain.wav" }
new Array:
z_b_pain;

new 
index;
for( 
index 0index sizeof zombie_classes_countindex++ ) {
    if( !
ArrayGetCellz_b_painindex ) )
       
ArraySetArrayz_b_painindexZOMBIE_PAINArraySizeZOMBIE_PAIN ) );
}
In natives:
        
z_b_pain ArrayCreate1); 
DavidLin is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-09-2016 , 19:12   Re: Array dimensions
Reply With Quote #2

Explain better what you are trying to do and attach the whole plugin that is causing the error.
__________________

Last edited by fysiks; 01-09-2016 at 19:13.
fysiks is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-11-2016 , 09:15   Re: Array dimensions
Reply With Quote #3

Why double [ ] [ ] ? Shouldnt it be unidimensional array?:

new const ZOMBIE_PAIN[ ]

Instead of

new const ZOMBIE_PAIN[ ][ ]

Last edited by siriusmd99; 01-11-2016 at 09:16.
siriusmd99 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-11-2016 , 19:38   Re: Array dimensions
Reply With Quote #4

Quote:
Originally Posted by siriusmd99 View Post
Why double [ ] [ ] ? Shouldnt it be unidimensional array?:

new const ZOMBIE_PAIN[ ]

Instead of

new const ZOMBIE_PAIN[ ][ ]
A string is a special type of array. So, when you have an array of strings, you have an array of arrays (aka a two dimensional array).
__________________
fysiks is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-12-2016 , 08:59   Re: Array dimensions
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
A string is a special type of array. So, when you have an array of strings, you have an array of arrays (aka a two dimensional array).
This was an retoric interogation. I know what is 2D array.
The issue is that he copies a 2d array to 1d , but i see that he has only one string so he doesnt need 2d array.
siriusmd99 is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-12-2016 , 12:42   Re: Array dimensions
Reply With Quote #6

Quote:
Originally Posted by siriusmd99 View Post
so he doesnt need 2d array.
Everybody make mistakes. Or he need it to pass to a function/native that requires 2-dimensional array. Example at a lower dimension:
Code:
    new info[ 1 ]     info[ 0 ] = mapIdx;             menu_additem( menu, choice, info )
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-12-2016 at 12:46. Reason: better info
addons_zz is offline
DavidLin
Member
Join Date: Jan 2016
Old 01-12-2016 , 12:48   Re: Array dimensions
Reply With Quote #7

I need 2d array because I'll add more sounds later on.
DavidLin is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-12-2016 , 12:53   Re: Array dimensions
Reply With Quote #8

Quote:
Originally Posted by DavidLin View Post
I need 2d array because I'll add more sounds later on.
So, consider using [ TUT ]Dynamic Array.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
DavidLin
Member
Join Date: Jan 2016
Old 01-12-2016 , 14:06   Re: Array dimensions
Reply With Quote #9

In fact that's how I've done it , this const is for default zombies if no classes are registered.
DavidLin is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-12-2016 , 15:07   Re: Array dimensions
Reply With Quote #10

Quote:
Originally Posted by DavidLin View Post
In fact that's how I've done it , this const is for default zombies if no classes are registered.
If you are goint to add more then u should set index of the string you understand?

ZOMBIE_PAIN[0]="s/zombie/pain.wav"
ZOMBIE_PAIN[1]="s/zombie/pain2.wav"
and so on...

so you should change :

ArraySetArray( z_b_pain, index, ZOMBIE_PAIN, ArraySize( ZOMBIE_PAIN ) );

to:

ArraySetArray( z_b_pain, index, ZOMBIE_PAIN[index], ArraySize( ZOMBIE_PAIN[index] ) );


PHP Code:

new const ZOMBIE_PAIN[ ][ ]     = { "s/zombie/pain.wav" ""}
new Array:
z_b_pain;

new 
index;
for( 
index 0index sizeof zombie_classes_countindex++ ) {
    if( !
ArrayGetCellz_b_painindex ) )
       
ArraySetArrayz_b_painindexZOMBIE_PAIN[index], ArraySizeZOMBIE_PAIN[index] ) );
}
In natives:
        
z_b_pain ArrayCreate1); 

Last edited by siriusmd99; 01-12-2016 at 15:09.
siriusmd99 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 09:22.


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