Jump to content

Recommended Posts

Posted

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'" );
Posted

! 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).

Posted

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
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...