Nerd-Rage Modders

Nerd-Rage Modders

Nerd-Rage Modders
 
HomeHomeFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Using the Function: StrTok

Go down 
AuthorMessage
Waffles



Posts : 12
Points : 46
Join date : 2010-03-05

PostSubject: Using the Function: StrTok   Sat Mar 13, 2010 9:01 pm

The function is:

Code:
StrTok( <string>, <delim> )

<string> can be in the form of a variable containing a string, or just a plain string.

<delim> is what is used to split the string.

Here is an example of the function in use:
Code:

CheckVIP()
{
   string = createdvar( "scr_vip_names", "Waffles::Xylozi", "", "", "string" );
   
   names = StrTok( string, "::" );

   for( i = 0; i < names.size; i++ )
   {         
      if( ToLower( self.name ) == ToLower( names[i] ) )
      {
         self.vip = true;
      }
      else
      {
         self.vip = false;
      }
   }
}

StrTok splits a string and turns the split strings into an array.

Code:
string = createdvar( "scr_vip_names", "Waffles::Xylozi", "", "", "string" );

Defines the variable with any values in the dvar. Uses a function called createdvar to make the dvar and set some default values.

Code:
names = StrTok( string, "::" );

This defines the variable "name" with the split strngs. String is the variable we defined earlier, and "::" is the delimiter, which is what is used to check were to split the string. This means string[0] returns "Waffles", and string[1] will return "Xylozi".

Code:
for( i = 0; i < names.size; i++ )

This uses the function of for(), which will loop through all the arrays of the variable names that are filled.

Code:
if( ToLower( self.name ) == ToLower( names[i] ) )

Makes the strings lowercase, ensure if they're the same they will match. Also used to check if they actually match, and therefore commit the code within the if statement.

StrTok can be used whenever you need to split a string, making it very useful for such functions as the VIP one above.

Hope this helped you understand StrTok. Smile
Back to top Go down
View user profile
 
Using the Function: StrTok
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Nerd-Rage Modders :: User Tutorial's :: Modding Tutorial's-
Jump to: