PDA

View Full Version : array sizes do not match, or destination array is too small


ATomas
05/05/2016, 09:53 AM
Hi,
i have little problem with array inicialization


#include <a_samp>

new Neco[10] = {0,...};//work fine

public OnFilterScriptInit()
{
Neco = {0,0,0,0,0,0,0,0,0,0};//work fine too, but its hard way
Neco = {0,...};//error, how to write this ?
return 1;
}


C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 029: invalid expression, assumed zero
C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 047: array sizes do not match, or destination array is too small

I don't want to use for, while, do or anything like this.
Thanks for any help.

Konstantinos
05/05/2016, 10:48 AM
Initialization is done on declaring only which the values are set to 0 by default anyway. For resetting, a loop would be what you need but you don't seem to want to do it for whatever reasons.

You can use memcpy instead:

new tmp[sizeof Neco];
memcpy(Neco, tmp, 0, sizeof tmp * 4, sizeof Neco);

ATomas
05/05/2016, 11:51 AM
Thanks for tip, but this

Neco = {0,0,0,0,0,0,0,0,0,0};

is still faster then

memcpy(Neco, tmp, 0, sizeof tmp * 4, sizeof Neco);

I looking for a very fast method

Dayrion
05/05/2016, 12:10 PM
This way ?
new Neco[10] = {0,...};//work fine

public OnFilterScriptInit()
{
Neco = {0,0,0,0,0,0,0,0,0,0};//work fine too, but its hard way
Neco[10] = {0,...};//Like this?
return 1;
}

I tried and there is no error message.

ATomas
05/05/2016, 12:22 PM
This way ?
new Neco[10] = {0,...};//work fine

public OnFilterScriptInit()
{
Neco = {0,0,0,0,0,0,0,0,0,0};//work fine too, but its hard way
Neco[10] = {0,...};//Like this?
return 1;
}

I tried and there is no error message.

Something like that, bud error message is

C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 032: array index out of bounds (variable "Neco")
C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 006: must be assigned to an array
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.

Nero_3D
05/05/2016, 12:22 PM
new Neco[10] = {0,...};//work fine
new dNeco[sizeof Neco];

public OnFilterScriptInit()
{
Neco = dNeco;
}

ATomas
05/05/2016, 12:24 PM
new Neco[10] = {0,...};//work fine
new dNeco[sizeof Neco];

public OnFilterScriptInit()
{
Neco = dNeco;
}

Its good idea.
Why
Neco = {0,...};
work only in 'new' and not work in code ?

Dayrion
05/05/2016, 12:40 PM
Something like that, bud error message is

C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 032: array index out of bounds (variable "Neco")
C:\Users\A\Desktop\samp037\filterscripts\test.pwn( 8) : error 006: must be assigned to an array
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.

I get no error... :eek:

EDIT : I got those errors on my main GM.