AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check width of string? (https://forums.alliedmods.net/showthread.php?t=83399)

redomin8 01-09-2009 03:44

Check width of string?
 
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!

Bad_Bud 01-09-2009 05:11

Re: Check width of string?
 
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.

Sn!ff3r 01-09-2009 07:25

Re: Check width of string?
 
@up
Quote:

new myString[6]
myString = "Hello" //INVALID!

Bad_Bud 01-09-2009 08:58

Re: Check width of string?
 
lol, okay so lets be big kids and pretend it said format.

Exolent[jNr] 01-09-2009 12:01

Re: Check width of string?
 
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.

redomin8 01-09-2009 14:46

Re: Check width of string?
 
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!

Bad_Bud 01-09-2009 14:53

Re: Check width of string?
 
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.

redomin8 01-09-2009 16:23

Re: Check width of string?
 
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

Bad_Bud 01-09-2009 23:29

Re: Check width of string?
 
Man, I wish I could tell you how I had done it...


All times are GMT -4. The time now is 09:13.

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