Author Topic: If Containing  (Read 1377 times)

How would I check to see if a variable contains something like if(%var Something "@Pig ") and then check the thing after it not using variables.

if( strPos( %var, "@Pig ") => 0 )

If you want case-insensitivity, use striPos instead.
Also, if you want to get the text after the occurrence of "@Pig ", use:
if( ( %pos = strPos( %var, "@Pig ") ) => 0 )
    %after = getSubStr( %var, %pos + strLen( "@Pig " ), strLen( %var ) )

if( strPos( %var, "@Pig ") => 0 )

If you want case-insensitivity, use striPos instead.
Also, if you want to get the text after the occurrence of "@Pig ", use:
if( ( %pos = strPos( %var, "@Pig ") ) => 0 )
    %after = getSubStr( %var, %pos + strLen( "@Pig " ), strLen( %var ) )

Syntax error in if( strPos( %var, "@Pig ") => 0 )

Uh, what. Make sure there isn't any extra/missing parenthesis or brackets above.

Uh, what. Make sure there isn't any extra/missing parenthesis or brackets above.
Code: [Select]
package atCommands {


function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
{
parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);

if(strPos(%msg,"@Test ") => 0))
{
%Word = getSubStr( %msg, %pos + strLen( "@Test " ), strLen( %var ) )
if(%Word $= "a")
{
commandToServer('messageSent',"Test: Success!");
}
}
}


}; activatePackage(atCommands);

if( strPos( %var, "@Pig ") => 0 )

If you want case-insensitivity, use striPos instead.
Also, if you want to get the text after the occurrence of "@Pig ", use:
if( ( %pos = strPos( %var, "@Pig ") ) => 0 )
    %after = getSubStr( %var, %pos + strLen( "@Pig " ), strLen( %var ) )


Just because you always try and correct people I had to do it.

It's not => jes, it's >= 0.

So change all of the => to >= lol.
« Last Edit: December 10, 2011, 11:18:21 AM by Superb »

Oh wow, haha. How did I not see that  :cookieMonster:

jes, you added a parentheses to the line. Also, I use strStr. Apparently, strStr and strPos do the same thing, but I've been used to using strStr.

jes, you added a parentheses to the line. Also, I use strStr. Apparently, strStr and strPos do the same thing, but I've been used to using strStr.
stripos has an additional offset parameter that i never seen anyone use

stripos has an additional offset parameter that i never seen anyone use

Which is?

str(i)Pos(%sourceString, %searchString[, %offset]);

strStr(%sourceString, %searchString);

I meant an example of what the offset is doing.

Meaning if you know there's going to be a chance that %searchString may be in there more than once, then you use offset if you only want the last one or something like that.

So it'd ignore first or second case? And no one told me this? All my scripting knowledge came from examples, and most of what I originally saw used strStr... Damn it.

I'm not exactly sure how to use it. I'm pretty sure it's position in the string.

So
striPos("i am a turtle i am strong","i am", 4);
would look for "i am" in " a turtle i am strong"