MAX_STRING+1 (why somebody use +1)
#1

Hello. I wanted to ask why it's used +1 with MAX_STRING ? If i don't use it, my server will be with some kind of bugs?
Reply
#2

What is the value of MAX_STRING and where is it being used? It is not a standard define from the SA-MP API as far as I can tell.

In order to tell if using MAX_STRING alone would cause problems, you would need to know the length of the string and where it is being used, so we can see how much length is required. Although I don't see a single cell making a huge difference.
Reply
#3

define MAX_STRING 128

new str[MAX_STRING+1];
it's used in format() and sscanf
Reply
#4

Well that's not enough information, but that length is the maximum length of the chat output. So that's probably why it's set to 128, although I don't know why they would be adding a single cell onto it.

The max output of the SA-MP chatbox is 128 characters, so I don't know why they are extending that to 129 characters in this instance.
Reply
#5

i.e. Some function's output requires 128 cells and you use MAX_STRING as 128 macro.

When you create a string it'll create 0 to 127, but if you want 128 cells you add 1, so It'll be 0 to 128.
Reply
#6

Quote:
Originally Posted by Luнs Miki
Посмотреть сообщение
i.e. Some function's output requires 128 cells and you use MAX_STRING as 128 macro.

When you create a string it'll create 0 to 127, but if you want 128 cells you add 1, so It'll be 0 to 128.
no because 0 is a cell to so you will have 129 cells, whhere 1 cell is useless.
Reply
#7

Thanks for the answers. I never used it and i think i won't use it in future. Because everything is fine with my scripts without +1
Reply
#8

If you for example see a code like this:
pawn Код:
new gPlayerRank[ MAX_PLAYERS + 1 ];
That is useless if you have defined MAX_PLAYERS the correct way, because it starts counting from 0 so that + 1 is not needed.

It is useful in some cases, for example:
pawn Код:
#define NUMBER_OF_TEAMS 2

CMD:removemyteam( playerid, params[ ] ) {
    SetPlayerTeam( playerid, NUMBER_OF_TEAMS + playerid + 1 );
    return 1;
}
You can use the NO_TEAM(or something like that) define instead, but I was just giving an example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)