AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array Sizes do not match (https://forums.alliedmods.net/showthread.php?t=56061)

slmclarengt 06-05-2007 18:27

Array Sizes do not match
 
Lines 639-640:
Code:

                get_user_origin ( i, origin[3] );
                FS_Should_Burn_Victim ( origin[3], burnvec1, burnvec2, radius, i, id, tempff );

Lines 399-403:
Code:

public FS_Should_Burn_Victim ( origin[], burnvec1[], burnvec2[], radius, i, id, ff )
{
        if ( ( is_user_alive ( i ) == 1 ) && ( i != id ) )
        {
                if ( ( get_distance ( origin, burnvec1 ) < radius ) || ( get_distance ( origin[3], burnvec2 ) < radius ) )

Why are lines 399-403 giving me
Code:

error 47: array sizes do not match...
Lines 639-640 are correct AFAIK, but 399-403 are reciprocating this error. I tried a variety of things but none worked.

Initialization of origin:
Code:

new origin[33][3];
I have been following the following threads/docs:
http://forums.alliedmods.net/showthr...%22array+sizes
www.doomworld.com/eternity/engine/smalldoc.pdf

Slmclarengt

regalis 06-05-2007 18:53

Re: Array Sizes do not match
 
Hi,
i think i know what is wrong in your script..

Code:

first: get_user_origin ( i, origin[i]);
second: FS_Should_Burn_Victim (origin[id], burnvec1, burnvec2, radius, i, id, tempff );
third: if ( ( get_distance ( origin, burnvec1 ) < radius ) || ( get_distance ( origin[i or id], burnvec2 ) < radius ) )


If you declare a array origin[3] you can do just get_user_origin(id, origin)

To send the array as a parameter in a function call just do function(origin)

And if you got an array origin[33][3] just declare the first dimension like get_user_origin(id, origin[id]) and function(origin[id])

Hope that helps :)

greetz regalis

Orangutanz 06-05-2007 18:58

Re: Array Sizes do not match
 
The problem is pretty self explanatory.

As regalis said you are not setting origin correctly! For retrieving and setting data it should have origin[id] since it is a 2 dimensional array.

Ideally you should use a declared size for arrays in your function.
1) For error checking if you try going beyond the size
2) So Pawn knows exactly how much memory to allocate.

Code:
public function1(id) {     new pOrigin[3]     get_user_origin(id, pOrigin)     function2(pOrigin) } function2(origin[3]) {     client_print(0, print_chat, "X: %i - Y: %i - Z: %i", origin[0], origin[1], origin[2]) }

slmclarengt 06-05-2007 19:11

Re: Array Sizes do not match
 
Thank you both for your help, but I still have not been able to remove that error.

Here's more code because I substituted what you guys said in, both ways, and neither worked:

PHP Code:

public FS_Should_Burn_Victim origin[], burnvec1[], burnvec2[], radiusiidff )
{
    if ( ( 
is_user_alive ) == ) && ( != id ) )
    {
        if ( ( 
get_distance origin[i], burnvec1 ) < radius ) || ( get_distance origin[i], burnvec2 ) < radius ) )
        {
            
TASK_Burn_Victim iidff );
        }
    }


and

PHP Code:

public TASK_Check_BurnZone idvec[], aimvec[], speed1speed2radius )
{
    new 
maxplayers get_maxplayers ( ) + 1;
    new 
tbodytid;
    
get_user_aiming idtidtbody550 );

    new 
ff 0;

    if ( 
cvar_exists "mp_friendlyfire" ) )
    {
        new 
ffcvar get_cvar_num "mp_friendlyfire" );

        if ( ( 
ffcvar == ) || ( ffcvar == ) )
        {
            
ff ffcvar;
        }
    }

    if ( ( 
tid ) && ( tid maxplayers ) )
    {
        
TASK_Burn_Victim tididff ) ;
    }

    new 
burnvec1[4],burnvec2[4],length1;

    
burnvec1[0]=aimvec[0]-vec[0];
    
burnvec1[1]=aimvec[1]-vec[1];
    
burnvec1[2]=aimvec[2]-vec[2];

    
length1=sqrt burnvec1[0]*burnvec1[0]+burnvec1[1]*burnvec1[1]+burnvec1[2]*burnvec1[2] );
    
burnvec2[0] = burnvec1[0] * speed2/length1;
    
burnvec2[1] = burnvec1[1] * speed2/length1;
    
burnvec2[2] = burnvec1[2] * speed2/length1;
    
burnvec1[0] = burnvec1[0] * speed1/length1;
    
burnvec1[1] = burnvec1[1] * speed1/length1;
    
burnvec1[2] = burnvec1[2] * speed1/length1;
    
burnvec1[0] += vec[0];
    
burnvec1[1] += vec[1];
    
burnvec1[2] += vec[2];
    
burnvec2[0] += vec[0];
    
burnvec2[1] += vec[1];
    
burnvec2[2] += vec[2];
    
    new 
origin[33][3];

    for ( new 
i=1<= maxplayersi++ ) 
    {        
        new 
tempff ff;

        if ( 
ff == )
        {
            if ( 
get_user_team(i) == get_user_team(id) )
            {
                
tempff 1;
            }
        }

        
get_user_origin iorigin[i] );
        
FS_Should_Burn_Victim origin[id], burnvec1burnvec2radiusiidtempff );
    }

    return 
PLUGIN_CONTINUE;


Slmclarengt

regalis 06-05-2007 19:21

Re: Array Sizes do not match
 
Are you sure that there have to be two times "i" in there?
Code:

if ( ( get_distance ( origin[i], burnvec1 ) < radius ) || ( get_distance ( origin[i], burnvec2 ) < radius ) )
I don't know what this code do...and im sorry that i have to go sleep...0o
Too tired right now.
Everything else looks good so far i can see...

greetz regalis

slmclarengt 06-05-2007 19:35

Re: Array Sizes do not match
 
I don't know what I need and what I don't because this is confusing me really badly. I have tried re-reading all docs/information on this subject but I think I just need someone else to help me with the issue directly.

Slmclarengt

pRED* 06-05-2007 19:57

Re: Array Sizes do not match
 
I'm pretty sure it will be the function headers..

Instead of being origin[], make it origin[3] etc etc.

[] is for strings, since vectors have a fixed sized you should specify this.

_Master_ 06-05-2007 20:07

Re: Array Sizes do not match
 
1) Verry sloppy for loop
2) Why did you do this
PHP Code:

new origin[33][3]; 

if you only use it to pass a single origin as a function call ?
3) The root of the problem is in here
PHP Code:

public FS_Should_Burn_Victim origin[], burnvec1[], burnvec2[], radiusiidff 

    if ( ( 
is_user_alive ) == ) && ( != id ) ) 
    { 
        if ( ( 
get_distance origin[i], burnvec1 ) < radius ) || ( get_distance origin[i], burnvec2 ) < radius ) ) 
        { 
            
TASK_Burn_Victim iidff ); 
        } 
    } 


Inside that function the "origin" variable is that from the argument line, NOT that one declared in your other function (where it was declared as private btw). You cannot do origin[i] here. Taking this a step forward: get_distance() expects 2 vectors like vec1[3] and vec2[3]; origin[i] is interpreted as origin[i][0], origin[i][1] and origin[i][2] (2D arrays). At this poin it conflicts with the local function argument origin[] (1D array). Review point 1 and 2 and your problem will get solved by itself.

slmclarengt 06-05-2007 20:23

Re: Array Sizes do not match
 
Quote:

Originally Posted by _Master_ (Post 486135)
1) Verry sloppy for loop
2) Why did you do this
PHP Code:

new origin[33][3]; 

if you only use it to pass a single origin as a function call ?
3) The root of the problem is in here
PHP Code:

public FS_Should_Burn_Victim origin[], burnvec1[], burnvec2[], radiusiidff 

    if ( ( 
is_user_alive ) == ) && ( != id ) ) 
    { 
        if ( ( 
get_distance origin[i], burnvec1 ) < radius ) || ( get_distance origin[i], burnvec2 ) < radius ) ) 
        { 
            
TASK_Burn_Victim iidff ); 
        } 
    } 


Inside that function the "origin" variable is that from the argument line, NOT that one declared in your other function (where it was declared as private btw). You cannot do origin[i] here. Taking this a step forward: get_distance() expects 2 vectors like vec1[3] and vec2[3]; origin[i] is interpreted as origin[i][0], origin[i][1] and origin[i][2] (2D arrays). At this poin it conflicts with the local function argument origin[] (1D array). Review point 1 and 2 and your problem will get solved by itself.

Thank you for the explanation but since this is code I am reviewing for someone else, I don't understand, therefore, I am getting the same error and I am too frustrated to think!!!

Current Code:
PHP Code:

public FS_Should_Burn_Victim origin[3], burnvec1[], burnvec2[], radiusiidff )
{
    if ( ( 
is_user_alive ) == ) && ( != id ) )
    {
        if ((
get_distance(origin[id],burnvec1) < radius) || (get_distance (origin[id],burnvec2) < radius ) )
        {
            
TASK_Burn_Victim iidff );
        }
    }


PHP Code:

public TASK_Check_BurnZone idvec[], aimvec[], speed1speed2radius )
{
    new 
maxplayers get_maxplayers ( ) + 1;
    new 
tbodytid;
    
get_user_aiming idtidtbody550 );

    new 
ff 0;

    if ( 
cvar_exists "mp_friendlyfire" ) )
    {
        new 
ffcvar get_cvar_num "mp_friendlyfire" );

        if ( ( 
ffcvar == ) || ( ffcvar == ) )
        {
            
ff ffcvar;
        }
    }

    if ( ( 
tid ) && ( tid maxplayers ) )
    {
        
TASK_Burn_Victim tididff ) ;
    }

    new 
burnvec1[4],burnvec2[4],length1;

    
burnvec1[0]=aimvec[0]-vec[0];
    
burnvec1[1]=aimvec[1]-vec[1];
    
burnvec1[2]=aimvec[2]-vec[2];

    
length1=sqrt burnvec1[0]*burnvec1[0]+burnvec1[1]*burnvec1[1]+burnvec1[2]*burnvec1[2] );
    
burnvec2[0] = burnvec1[0] * speed2/length1;
    
burnvec2[1] = burnvec1[1] * speed2/length1;
    
burnvec2[2] = burnvec1[2] * speed2/length1;
    
burnvec1[0] = burnvec1[0] * speed1/length1;
    
burnvec1[1] = burnvec1[1] * speed1/length1;
    
burnvec1[2] = burnvec1[2] * speed1/length1;
    
burnvec1[0] += vec[0];
    
burnvec1[1] += vec[1];
    
burnvec1[2] += vec[2];
    
burnvec2[0] += vec[0];
    
burnvec2[1] += vec[1];
    
burnvec2[2] += vec[2];
    
    new 
origin[3];

    for ( new 
i=1<= maxplayersi++ ) 
    {        
        new 
tempff ff;

        if ( 
ff == )
        {
            if ( 
get_user_team(i) == get_user_team(id) )
            {
                
tempff 1;
            }
        }

        
get_user_origin iorigin );
        
FS_Should_Burn_Victim originburnvec1burnvec2radiusiidtempff );
    }

    return 
PLUGIN_CONTINUE;


Whoever can fix it gets praise b/c it has pissed me off for more than an hour too long!!!!!!!!!!!!!!!!!

Slmclarengt

_Master_ 06-05-2007 20:27

Re: Array Sizes do not match
 
One more thing:
PHP Code:

new burnvec1[4],burnvec2[4

should be
PHP Code:

new burnvec1[3],burnvec2[3

I do believe this issues the error


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

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