help | some error
#3

Quote:
Originally Posted by rong13
pawno\myadminscript.pwn(161) : error 047: array sizes do not match, or destination array is too small
Alright, looking at the error, the fix should be pretty simple.

I did not look through your script, but I'll try to explain you what your problem is.

So, when creating an array in pawn, you declare it like:

pawn Код:
new array[5];
Once the array was created, you will use its space for something like a number. So, now it is important to know that the array we declared can hold five numbers. Alot tend to do:

Example 1:
pawn Код:
main()
{
  array[1] = 23;
  array[2] = 24;
  array[3] = 25;
  array[4] = 26;
  array[5] = 26;
}
On the first look, this looks totally fine to some people but yet is wrong. When declaring an array in pawn, you shall never use the last number. So, instead of the above example, your code should look like:

Example 2:
pawn Код:
main()
{
  array[0] = 23;
  array[1] = 24;
  array[2] = 25;
  array[3] = 26;
  array[4] = 26;
}

So, when using the code I gave you from example 1, it will cause this error:
Код:
error 032: array index out of bounds (variable "array")
So, when looking at your error:
Код:
error 047: array sizes do not match, or destination array is too small
This just means that the array you tried to copy was either to big or the destination too small, hence both is the same.

So, when you do:

pawn Код:
new array[30];
And now, we use this to determine something in a function, e.g:

pawn Код:
stock function(String[], args)
{
  array = Strings;
}
We are causing a problem. Strings is not given any defined length so it could be bigger then the array we declared. This will cause the compiler to complain, just like it did for you. So, As I just took a look at your script:

pawn Код:
new tmp[30],
   tmp2[30],
   index;
tmp = strtok(params, index);
Caused one of the errors, you can already see the problem. params[] is only internly given a max length and that is 255 characters. So, to make TMP be able to hold the maximum the variable params could hold, you have to give tmp 256 cells. E.g:

pawn Код:
new tmp[256];
As this is very inefficient because it uses alot of the stock from your dynamic memory within the function, you can also, as I already noticed you using dcmd, use sscanf made by ******. This will safe you the variable TMP and make you save some heap size and optimize your code even more. Just search for sscanf.
Reply


Messages In This Thread
help | some error - by rong13 - 12.10.2009, 19:09
Re: help | some error - by Peter_Corneile - 12.10.2009, 21:25
Re: help | some error - by Extremo - 12.10.2009, 21:50
Re: help | some error - by rong13 - 13.10.2009, 04:50

Forum Jump:


Users browsing this thread: 1 Guest(s)