Would this work?
#1

So, when it comes to script optimization( specially to the smart use of strings length) you would find me create a string new str[250] just to display a message like Welcome Back!
So I started focussing on change the way I work into a cleaner one, well, while I was working on something a couple of hours ago, it occurred to me something that can use as much low string size to store player's name, something much smaller than MAX_PLAYER_NAME, and then I wondered, what if I used this
PHP Code:
#define P_NAME strlen(GetName(%0))
GetName(playerid){
    new 
name_str[MAX_PLAYER_NAME];
    
GetPlayerName(playeridname_strsizeof(name_str));
    return 
name_str;

I don't know if this would work or not, so I wanted to ask you guys, what do you thing?
Reply
#2

You can't declare arrays with size unknown at compile-time, so the following code is invalid and will result in a compilation error:
Code:
new str[PNAME(x)];
Reply
#3

Quote:
Originally Posted by Spmn
View Post
You can't declare arrays with size unknown at compile-time, so the following code is invalid and will result in a compilation error:
Code:
new str[PNAME(x)];
thanks for the fast reply
Reply
#4

The more cells you define, the slower it gets. That's why it's recommended to use a number that is close to what you will need.

For client messages, set it to 144. You can't use any more than that.
Reply
#5

It would have been nice if pawn supported dynamic allocation of arrays.
Reply
#6

y_malloc allows dynamic allocation, but I'm certain 99% of people don't have the need for anything other than static allocation. I'd rather go with smarter compiler which doesn't take ages to allocate arrays.
Reply
#7

just use new s[24];
Reply
#8

Quote:
Originally Posted by CodeStyle175
View Post
just use new s[24];
MAX_PLAYER_NAME + 1 is actually "more correct".
Reply
#9

no....
Reply
#10

Quote:
Originally Posted by CodeStyle175
View Post
no....
SickAttack is right, MAX_PLAYER_NAME + 1(Null terminator).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)