Player name from inputtext
#1

Hello. Im have problem while trying to get player name from inputtext. My code:

Код:
new name[MAX_PLAYER_NAME] = inputtext;
But when i compiling, i getting this error: error 008: must be a constant expression; assumed zero

Whats the problem?
Reply
#2

pawn Код:
new name[MAX_PLAYER_NAME];
format(name,sizeof(name),"%s",inputtext);
return 1;
?
Reply
#3

Working! Thanks
Reply
#4

Quote:
Originally Posted by Daslee
Посмотреть сообщение
Working! Thanks
Its generally never a good idea to assign strings using the assignment operator. In most languages it simply isnt allowed as it can lead to buffer overflows. The ONLY time you should use the assignment opertator is if you're absolutely sure the strings are the same size.

The reason this didnt work is because inputtext's size isnt known during compile time, therefor its an invalid assignment (someone could type something much longer than 24 characters).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)