Johxz Posted March 29, 2015 Posted March 29, 2015 In the tutorial doc use this example !strcmp I was thinking that is Logical NOT, but isn't. Someone can explain this to me? if(!strcmp(%userName, "Heather")) echo("User Found: " @ %userName); else if(%userName $= "Mich") echo("User Found: " @ %userName); else echo("User " @ %userName @ " not found"); From the Tscript reference use this example. What is the difference?if( strcmp( %var, "foobar" ) == 0 ) echo( "%var is equal to 'foobar'" ); Quote
JeffH Posted March 29, 2015 Posted March 29, 2015 both are equivalent. !strcmp is the same thing as strcmp == 0. When the strings are equal, it returns 0. Quote
buckmaster Posted March 29, 2015 Posted March 29, 2015 ! is the boolean negation operator (it means not). !0==1 and !1==0 (and, IIRC, !2==0, !#==0, etc.). strcmp returns 0 if the two strings are equal, so !strcmp will return 1 if they're equal (or 0 if they're not equal). Quote
Johxz Posted March 29, 2015 Author Posted March 29, 2015 Is this correct? // Testing 1 function matchNum1(%numBer) { if(strcmp(%numBer, "0")) echo("Number 0 Found."); else if(strcmp(%numBer, "1")) echo("Number 1 Found."); else echo("Number " @ %numBer @ " not found"); } Output:matchNum1(0); Number 1 Found matchNum1(1); Number 0 Found // Testing 2 function matchNum2(%numBer) { if(!strcmp(%numBer, "0")) echo("Number 0 Found."); else if(!strcmp(%numBer, "1")) echo("Number 1 Found."); else echo("Number " @ %numBer @ " not found"); } Output:matchNum2(0); Number 0 Found matchNum1(1); Number 1 Found Quote
Johxz Posted March 31, 2015 Author Posted March 31, 2015 hahaha so sorry mate :lol: I was a little tired that day :oops: I use my free time to learn t3d... Quote
JeffR Posted April 1, 2015 Posted April 1, 2015 Hey, people gotta learn what strcmp is/does at some point in time. It's no biggie.Also, in TS, there's a string comparitor operator if(%myString $= "ThingIWantToCheck") return "woo"; if(%myString !$= "ThingIWantToCheck") return "boo"; If you know you're dealing with strings, it can be a bit easier to just use that instead of using the strcmp function. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.