AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array dimensions (https://forums.alliedmods.net/showthread.php?t=277482)

DavidLin 01-09-2016 18:18

Array dimensions
 
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); 


fysiks 01-09-2016 19:12

Re: Array dimensions
 
Explain better what you are trying to do and attach the whole plugin that is causing the error.

siriusmd99 01-11-2016 09:15

Re: Array dimensions
 
Why double [ ] [ ] ? Shouldnt it be unidimensional array?:

new const ZOMBIE_PAIN[ ]

Instead of

new const ZOMBIE_PAIN[ ][ ]

fysiks 01-11-2016 19:38

Re: Array dimensions
 
Quote:

Originally Posted by siriusmd99 (Post 2382205)
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).

siriusmd99 01-12-2016 08:59

Re: Array dimensions
 
Quote:

Originally Posted by fysiks (Post 2382377)
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.

addons_zz 01-12-2016 12:42

Re: Array dimensions
 
Quote:

Originally Posted by siriusmd99 (Post 2382502)
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 )

DavidLin 01-12-2016 12:48

Re: Array dimensions
 
I need 2d array because I'll add more sounds later on.

addons_zz 01-12-2016 12:53

Re: Array dimensions
 
Quote:

Originally Posted by DavidLin (Post 2382566)
I need 2d array because I'll add more sounds later on.

So, consider using [ TUT ]Dynamic Array.

DavidLin 01-12-2016 14:06

Re: Array dimensions
 
In fact that's how I've done it :D, this const is for default zombies if no classes are registered.

siriusmd99 01-12-2016 15:07

Re: Array dimensions
 
Quote:

Originally Posted by DavidLin (Post 2382605)
In fact that's how I've done it :D, 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); 



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

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