Raised This Month: $32 Target: $400
 8% 

Solved How use split_string?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 03-24-2020 , 20:38   How use split_string?
Reply With Quote #1

I wrote the following code.
But output all zero..
PHP Code:
new color[3];
new 
sColor[12]; // max 255,255,255
new sPart[4];
new 
sPartLen  charsmax(sPart);
new 
sColorLen charsmax(sColor);

get_pcvar_string(COLOR_CTsColorsColorLen); // COLOR_CT = 0,0,255

new 00ridx 0;
while((
split_string(sColor[ridx], ","sPartsPartLen)) != -1)
{
    
ridx += i;
    
color[n++] = str_to_num(sPart);
    
server_print(sPart); // All zero....

Is this usage correct?
__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 03-25-2020 at 06:08.
+ARUKARI- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2020 , 20:52   Re: How use split_string?
Reply With Quote #2

Show what the source string looks like and what you expect to parse from it.
__________________
Bugsy is online now
JusTGo
Veteran Member
Join Date: Mar 2013
Old 03-24-2020 , 20:52   Re: How use split_string?
Reply With Quote #3

https://www.amxmodx.org/api/string/split_string

From the documentation split_string should accept the source string, but you are giving it only one letter
try to change it to :

split_string(sColor, ",", sPart, sPartLen))
__________________
JusTGo is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2020 , 20:59   Re: How use split_string?
Reply With Quote #4

PHP Code:
new szRGB[] = "251,252,253";
new 
szR] , szG] , szB];
new 
RGB];
    
replace_allszRGB charsmaxszRGB ) , "," " " );
parseszRGB szRcharsmaxszR ) , szG charsmaxszG ) , szB charsmaxszB ) );

RGB] = str_to_numszR );
RGB] = str_to_numszG );
RGB] = str_to_numszB ); 
__________________
Bugsy is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-24-2020 , 21:47   Re: How use split_string?
Reply With Quote #5

Quote:
Originally Posted by JusTGo View Post
https://www.amxmodx.org/api/string/split_string

From the documentation split_string should accept the source string, but you are giving it only one letter
try to change it to :

split_string(sColor, ",", sPart, sPartLen))
Technically, when you pass an indexed string to a function that expects a string, it will pass the string starting from the indexed location until the end of the string. E.g.

PHP Code:
new szString[] = "Hello World!"
server_print("%s"szString[6]) 
will result in "World!".
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2020 , 21:54   Re: How use split_string?
Reply With Quote #6

Yea, to make this work you'd need to format it like "255,255,255,"
PHP Code:
new szRGBString[] = "251,252,253,";
new 
szRGB][ ];
new 
iPos;
    
while ( 
iPos sizeofszRGB ) )
{
    
+= split_stringszRGBString] , "," szRGBiPos++ ] , charsmaxszRGB[] ) );
}
    
server_print"%s %s %s" ,szRGB] , szRGB] , szRGB] ); 
__________________
Bugsy is online now
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 03-24-2020 , 22:02   Re: How use split_string?
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
Yea, to make this work you'd need to format it like "255,255,255,"
PHP Code:
new szRGBString[] = "251,252,253,";
new 
szRGB][ ];
new 
iPos;
    
while ( 
iPos sizeofszRGB ) )
{
    
+= split_stringszRGBString] , "," szRGBiPos++ ] , charsmaxszRGB[] ) );
}
    
server_print"%s %s %s" ,szRGB] , szRGB] , szRGB] ); 
oh wait..
last comma required?

0,0,255 => output:0 0 0(N/A)
0,0,255,=> output:0 0 255 yeah?!

Well, I'll try it when I get home.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2020 , 22:32   Re: How use split_string?
Reply With Quote #8

Using split_string(), yes. I personally would use my code using parse() above.
__________________
Bugsy is online now
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 03-25-2020 , 06:08   Re: How use split_string?
Reply With Quote #9

OK working.

Pattern A:
PHP Code:
new tcolor    [3];
new 
sRGB    [13];
new 
sColor[4];
new 
sRGBLen     charsmax(sRGB);
new 
sColorLen    charsmax(sColor[]);
new 
00iPos 0;

get_pcvar_string(COLOR_CTsRGBsRGBLen);
formatex(sRGBsRGBLen"%s%s"sRGB",");

while(
sizeof(tcolor))
{
    
split_string(sRGB[iPos += i], ","sColorsColorLen);
    
tcolor[n++] = str_to_num(sColor);

Pattern B:
PHP Code:
new tcolor    [3];
new 
sRGB    [13];
new 
sColor[3][4];
new 
sRGBLen     charsmax(sRGB);
new 
sColorLen    charsmax(sColor[]);

get_pcvar_string(COLOR_CTsRGBsRGBLen);

replace_all(sRGBsRGBLen","" ");
parse(sRGBsColor[0], sColorLensColor[1], sColorLensColor[2], sColorLen);
while(
sizeof(tcolor))
    
tcolor[n] = str_to_num(sColor[n++]); 
Pattern B is simply.
thanks all.
I knew how to use it so I solved it.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Reply


Thread Tools
Display Modes

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 10:21.


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