SA-MP Forums Archive
Player name from inputtext - 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: Player name from inputtext (/showthread.php?tid=269541)



Player name from inputtext - Daslee - 16.07.2011

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?


Re: Player name from inputtext - blackwave - 16.07.2011

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


Re: Player name from inputtext - Daslee - 16.07.2011

Working! Thanks


Re: Player name from inputtext - Kyosaur - 16.07.2011

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).