Raised This Month: $51 Target: $400
 12% 

Multiple integers out of a string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Player 1
Member
Join Date: Apr 2012
Old 12-02-2012 , 17:29   Multiple integers out of a string
Reply With Quote #1

I want to allow users to set HudText colors with a single Convar. I have the convar set to:
sm_warmup_text_color "21 238 211"
but it isn't working properly. my PrintToChat debug returns:
21
238
38

Theres obviously a problem reading that string, but I can't figure out where it's going wrong.
PHP Code:
GetHudTextColors()
{
    new 
leni;
    
decl String:Colors[16], String:Temp[16];
    
GetConVarString(g_Handle[WarmupTextColor], Colors16);
    
    for (
0<= 2i++)
    {
        
len BreakString(Colors[len], Temp16);
        
g_iTextColor[i] = StringToInt(Temp);
        
        if (
g_iTextColor[i] < || g_iTextColor[i] > 255)
            
g_iTextColor[i] = 0;
        
        
PrintToChatAll("%d"g_iTextColor[i]);
    }

Player 1 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-02-2012 , 18:21   Re: Multiple integers out of a string
Reply With Quote #2

Use:

Code:
len += BreakString(Colors[len], Temp, sizeof(Temp));
This is because, on the second loop of your BreakString, it returns 4 (since your next string is 4 characters away, starting at Colors[3]), and the String at Colors[4] on the third and final iteration is "38". Using the above fix will keep track of the entire length of the string, instead of just the current substring.

I'd also recommend making a habit of using sizeof(Temp) in place of 16 on the first line within the for-loop.
__________________

Last edited by 11530; 12-02-2012 at 18:41.
11530 is offline
Player 1
Member
Join Date: Apr 2012
Old 12-02-2012 , 20:17   Re: Multiple integers out of a string
Reply With Quote #3

Right! Thanks so much
Player 1 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-02-2012 , 20:49   Re: Multiple integers out of a string
Reply With Quote #4

See Also: ExplodeString.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 12:51.


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