SA-MP Forums Archive
MAX_STRING+1 (why somebody use +1) - 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: MAX_STRING+1 (why somebody use +1) (/showthread.php?tid=272479)



MAX_STRING+1 (why somebody use +1) - BuLLeT[LTU] - 28.07.2011

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?


Re: MAX_STRING+1 (why somebody use +1) - JaTochNietDan - 28.07.2011

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.


Re: MAX_STRING+1 (why somebody use +1) - BuLLeT[LTU] - 28.07.2011

define MAX_STRING 128

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


Re: MAX_STRING+1 (why somebody use +1) - JaTochNietDan - 28.07.2011

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.


Re: MAX_STRING+1 (why somebody use +1) - steki. - 28.07.2011

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.


Re: MAX_STRING+1 (why somebody use +1) - Gamer_Z - 28.07.2011

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.


Re: MAX_STRING+1 (why somebody use +1) - BuLLeT[LTU] - 28.07.2011

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


Re: MAX_STRING+1 (why somebody use +1) - Mean - 28.07.2011

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.