SA-MP Forums Archive
help | some error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: help | some error (/showthread.php?tid=101911)



help | some error - rong13 - 12.10.2009

i start to create admin script from these page
https://sampwiki.blast.hk/wiki/Creating_...rScript#Logout
and i have errors when i get to password
errors:
C:\Documents and Settings\шеп\My Documents\games\gta sa mp server\pawno\myadminscript.pwn(161) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\шеп\My Documents\games\gta sa mp server\pawno\myadminscript.pwn(164) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

http://pastebin.com/f6d632bfb
so what the problom


Re: help | some error - Peter_Corneile - 12.10.2009

I dont know what you did wrong (too lazy to check) but this is what i made from the same page and compiles

http://pastebin.com/d19c77d5c


Re: help | some error - Extremo - 12.10.2009

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.


Re: help | some error - rong13 - 13.10.2009

Quote:
Originally Posted by [NT
Extremo ]
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 Код:
tanks dude
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.