Raised This Month: $ Target: $400
 0% 

get_user_name question.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-29-2011 , 14:33   get_user_name question.
Reply With Quote #1

I searched funcwiki, but I still doesn't knwo what len means in this code:
PHP Code:
get_user_name indexname[], len 
FuncWiki
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-29-2011 at 14:34.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-29-2011 , 14:44   Re: get_user_name question.
Reply With Quote #2

PHP Code:
new szName[33]
get_user_name(idszNamecharsmax(szName)) 
or

PHP Code:
new szName[33]
get_user_name(id szName32
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 15:02   Re: get_user_name question.
Reply With Quote #3

Len stands for the max length of the string.
The max length is the size of your array - 1 (for the NULL terminator);
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 15:09   Re: get_user_name question.
Reply With Quote #4

Always use charsmax() and not a hard-coded number. You almost always need to set a 'max-characters' value to a function putting info into a string. charsmax( StringVariable ) retrieves the correct value.
__________________
Bugsy is offline
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 10-29-2011 , 15:13   Re: get_user_name question.
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Always use charsmax() and not a hard-coded number.
Why I need to use charsmax? I know, I'll never change the maxlength of the username. And 32 is enough.
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-29-2011 , 15:17   Re: get_user_name question.
Reply With Quote #6

Quote:
Originally Posted by Flipper_SPb View Post
Why I need to use charsmax? I know, I'll never change the maxlength of the username. And 32 is enough.
Because if you get in the [good] habit of using it then you will less likely make mistakes with other strings when changing the array length. That is my reason maybe others have their own reasons.
__________________
fysiks is offline
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-29-2011 , 15:20   Re: get_user_name question.
Reply With Quote #7

Why can't I use it like this?
PHP Code:
if(get_user_name idEvaldas.Grigas )) 
I want to check if player name is Evaldas.Grigas.
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-29-2011 at 15:20.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 10-29-2011 , 15:21   Re: get_user_name question.
Reply With Quote #8

How fast is charsmax()? Is it good to use it in ClientPreThink instead of hard-coded values?
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 10-29-2011 , 15:23   Re: get_user_name question.
Reply With Quote #9

Quote:
Originally Posted by Evaldas.Grigas View Post
Why can't I use it like this?
PHP Code:
if(get_user_name idEvaldas.Grigas )) 
.
Because it totally wrong.

PHP Code:
new szName[33]
get_user_name(idszNamecharsmax(szName))  

if(
equal(szName"Evaldas.Grigas"))
{

   
//your code


__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 15:24   Re: get_user_name question.
Reply With Quote #10

There's no reason not to plus its a good habit that can prevent errors and provide easier debugging on future revisions. I am now rewriting a plugin I wrote years ago and it took me a while to realize the cause of one of my errors where I added items to an array and in my for-loop I had the size hard-coded, had I used sizeof() my code would have adjusted itself for this change.

Quote:
Originally Posted by Flipper_SPb View Post
How fast is charsmax()? Is it good to use it in ClientPreThink instead of hard-coded values?
It is fine to use anywhere in code. It is a macro so when your code is compiled the compiler replaces each occurrence of sizeof/charsmax with the numerical value. You are thinking of a native function which calls a dll which are good to avoid using when possible.
__________________

Last edited by Bugsy; 10-29-2011 at 15:34.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode