1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

String comparison in a mutator?

Discussion in 'Infiltration Development' started by The Great Sephiroth, Apr 26, 2013.

  1. The Great Sephiroth

    The Great Sephiroth New Member

    Joined:
    May 18, 2004
    Messages:
    32
    Likes Received:
    0
    I am working on a mutator for Inf 2.9 CE that will tweak the bots a bit, such as not being able to see through tree textures that we cannot see through. A few maps are currently nearly impossible to win if bots are your opponents due to so much foliage that humans cannot see bots, but bots can see humans anywhere.

    Part of my code needs to do a string comparison when compiled in debug mode and I cannot figure out how to do it in UT99. I used a function that Wormbo created some time ago, but the function will not compile with Infiltration and I cannot determine why. Can somebody help me figure this out?
    Code:
    static final function int StrCmp(coerce string S, coerce string T, optional int Count = MaxInt, optional bool bCaseSensitive = False)
    {
      S = Left(S, Count);
      T = Left(T, Count);
      if (bCaseSensitive ? (S == T) : (S ~= T))
        return 0;
    
      return (bCaseSensitive ? (S > T) : (Caps(S) > Caps(T))) ? 1 : -1;
    }
    
    I am told that the function declaration is missing an ending paranthesis ")" when attempting to compile. I must be missing something. Maybe I am mixing some UT03/04 or UT3 in here and not catching it. It has been several years sicne I last used UT99 UnrealScript.
     
  2. meowcat

    meowcat take a chance

    Joined:
    Jun 7, 2001
    Messages:
    798
    Likes Received:
    3
    As I recall the '?' operator/function does not exist in UT, or UT2k4 (though I wish it did!) (and darn, I'm forgetting the exact syntax for the use of it). I think you are going to need to rewrite that to be something like this (untested, and I think I've may have swapped your intended return values):
    Code:
    static final function int StrCmp(coerce string S, coerce string T, optional int Count, optional bool bCaseSensitive)
    {
      [COLOR="Blue"]if(Count == 0) Count = MaxInt; // since the default value for optional variables if usually null/0/0.0 etc.[/COLOR]
      S = Left(S, Count);
      T = Left(T, Count);
    [COLOR="Blue"]  if ( bCaseSensitive ) {
        if(S == T) return 0;
        else if(Caps(S) > Caps(T)) return -1;
        return 1;
      }
      else  {
        if(S ~= T) return 0;
        else if(S > T) return -1;
        return 1;
      }[/COLOR]
    }
    
     
  3. dr.flay

    dr.flay Dr.Flay™

    Joined:
    Sep 19, 2011
    Messages:
    397
    Likes Received:
    3
  4. The Great Sephiroth

    The Great Sephiroth New Member

    Joined:
    May 18, 2004
    Messages:
    32
    Likes Received:
    0
    I already figured it out. I was thinking of using StrCmp but UT99 has InStr, which works flawlessly. Also, the if statement shorthand does not exist in UT99 as was mentioned by meowcat. I am a C++ programmer and use shorthand, but forgot that UT99 does not accept it. Thank you for the responses though!
     

Share This Page