Raised This Month: $ Target: $400
 0% 

Check width of string?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redomin8
Member
Join Date: Feb 2005
Old 01-09-2009 , 03:44   Check width of string?
Reply With Quote #1

Is there a way to measure the width of a string?
I have a HUD display aligned on the right side of the screen, and would like to keep a set margin from the right. Simply hard-coding it a certain distance away is not ideal. Thanks!
__________________
"Your momma's so dumb she required a cvar to turn the tv on." - Inspired by Speed!
redomin8 is offline
Send a message via AIM to redomin8
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-09-2009 , 05:11   Re: Check width of string?
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=35

This will tell you how long a string is.

If you're curious (or if I'm just being an ass and you already knew), what this function does is check each cell of the array until it encounters an integer value of zero, since strings in pawn are actually arrays of integers that correspond to ASCII values.

Ex:
PHP Code:
new String[1337]
String="Your mother."
 
strlen(String) 
strlen(String) will return the integer 12, because the function will find that String[12]==0, because String[12] is the cell of the array directly after the last character in the string.
__________________

Last edited by Bad_Bud; 01-09-2009 at 05:15.
Bad_Bud is offline
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 01-09-2009 , 07:25   Re: Check width of string?
Reply With Quote #3

@up
Quote:
new myString[6]
myString = "Hello" //INVALID!
__________________
Join US - custom Zombie Server - Custom Addons:



Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-09-2009 , 08:58   Re: Check width of string?
Reply With Quote #4

lol, okay so lets be big kids and pretend it said format.
__________________
Bad_Bud is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-09-2009 , 12:01   Re: Check width of string?
Reply With Quote #5

Apparently, the OP doesn't know much about Pawn/AMXX scripting.
Therefore, he/she would think that anything you post is correct.
If you always post correct code, there won't be any problems for new scripters.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
redomin8
Member
Join Date: Feb 2005
Old 01-09-2009 , 14:46   Re: Check width of string?
Reply With Quote #6

Thanks for the help, but I am not looking for the length in characters. I am looking for a width of the characters combined ('w' and 'i' dont share the same width)

See http://www.thescarms.com/dotnet/MeasureString.aspx for an example of what I mean. Thanks!
__________________
"Your momma's so dumb she required a cvar to turn the tv on." - Inspired by Speed!
redomin8 is offline
Send a message via AIM to redomin8
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-09-2009 , 14:53   Re: Check width of string?
Reply With Quote #7

In that case... I believe part of one of my plugins (not submitted) had a hud on the right side of the screen. I'm pretty sure it just let me right justify it, and that's all you need to worry about. Don't have the code with me (travelling) so I can't copy pasta for you... sorry.

I just looked at the funcwiki and I have no idea what you would do to accomplish this.
__________________
Bad_Bud is offline
redomin8
Member
Join Date: Feb 2005
Old 01-09-2009 , 16:23   Re: Check width of string?
Reply With Quote #8

I didnt know they had a right justify! Currently im using

set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)

and
const Float:HUD_STATS_X = 0.92
const Float:HUD_STATS_Y = 0.9

To get to the right side
__________________
"Your momma's so dumb she required a cvar to turn the tv on." - Inspired by Speed!
redomin8 is offline
Send a message via AIM to redomin8
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-09-2009 , 23:29   Re: Check width of string?
Reply With Quote #9

Man, I wish I could tell you how I had done it...
__________________
Bad_Bud 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 09:13.


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