Weird Problem about Arrays !!! Somebody tell me what's going on please..
#6

Let me tell you why you have those errors:

Let us start out with analyzing your first code:

pawn Код:
enum Houses
{
    HouseName[64],
    HouseOwner[64],
    HouseLocation[64],
}
new HouseInfo[MAX_HOUSES][Houses];

//These scripts are the errors:
HouseInfo[h][HouseName] = "Unowned House";
HouseInfo[h][HouseOwner] = "Nobody";
If you look at the first error line in your code submitted above, you will see that you defined "HouseName" to have a length of 64. That means 63 letters/slots available (including the null terminating the string). In that first error line, the "string" is not matching the size of the "HouseName". The string you wrote is the same defining the lenght as 14. So, that means: 64 and 14 does not match do they? That is what the error tells you.


So, If you write:

pawn Код:
new str[64];
format(str, sizeof(str), "Unowned House");
HouseInfo[h][HouseName] = str;
format(str, sizeof(str), "Nobody");
You define a string with 64 slots (which is the same size as f.ex the "HouseName"). When you "format" something, you just replace characters in the pre-defined string with the ones you want:

Before formatting:
pawn Код:
//str:
str[0] --> \0
str[1] --> \0
str[2] --> \0
str[3] --> \0
str[4] --> \0
str[5] --> \0
str[6] --> \0
str[7] --> \0
str[8] --> \0
str[9] --> \0
str[10] --> \0
str[11] --> \0
str[12] --> \0
str[13] --> \0
str[14] --> \0
...
str[63] --> \0
After formatting:
pawn Код:
//str after formatting it:
str[0] -->U
str[1] -->n
str[2] -->o
str[3] -->w
str[4] -->n
str[5] -->e
str[6] -->d
str[7] -->
str[8] -->h
str[9] -->o
str[10] -->u
str[11] -->s
str[12] -->e
str[13] -->\0
str[14] -->\0
...
str[63] -->\0

That makes the strings match, and you don't get any errors-


I might have a few mistakes, but i really hope you get the point. That is the difference doing what you did without formatting and the one where you formatted.

Greetings
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)