Results 1 to 8 of 8

Thread: Really odd, function returning string only works for 1 if statement

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Really odd, function returning string only works for 1 if statement

    So I have a function that gets the players position:

    Simba Code:
    function GetMyPos():string;
    begin
      if FindIconDist(7394286, 13, 15, 0.03, 0.88) and FindIconDist(3174424, 8, 60, 0.20, 2.20) then
      begin
        result := 'bank';
        exit;
      end;
      if (FindIconDist(8602720, 6, 25, 0.06, 0.41) and FindIconDist(16206088, 6, 27, 0.12, 0.02)) then
      begin
        result := 'Stone';
        exit;
      end;
      if (FindIconDist(229374, 3, 25, 2.11, 0.42) and seeWater) then
      begin
        result := 'Alter';
        exit;
      end else
        Result := 'Unknown';
    end;

    (takes 16 ms and works fine tyvm)

    And to find out were I am I do:

    Simba Code:
    Writeln(GetMyPos);

    And it outputs the correct spot

    BUT When ever I try to do this:

    Simba Code:
    if (GetMyPos = 'Alter') then secretprocedure;
     if (GetMyPos = 'Bank') then LocateBank;

    If im at the alter it will do secret procedure, but if i'm at the bank it won't do locatebank (and yes it can find the bank)

    Any reason why I can't use the function returning a string for more then 1 if statements? Do I have to use a global variable?

  2. #2
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Remove the 'end else Result := 'Unknown';' and move Result := 'Unknown'; to the beginning of the function.

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    Remove the 'end else Result := 'Unknown';' and move Result := 'Unknown'; to the beginning of the function.
    Done, problem still persists (or was that a tip?)

  4. #4
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    So I have a function that gets the players position:

    Simba Code:
    function GetMyPos():string;
    begin
      if FindIconDist(7394286, 13, 15, 0.03, 0.88) and FindIconDist(3174424, 8, 60, 0.20, 2.20) then
      begin
        result := 'bank';
        exit;
      end;
      if (FindIconDist(8602720, 6, 25, 0.06, 0.41) and FindIconDist(16206088, 6, 27, 0.12, 0.02)) then
      begin
        result := 'Stone';
        exit;
      end;
      if (FindIconDist(229374, 3, 25, 2.11, 0.42) and seeWater) then
      begin
        result := 'Alter';
        exit;
      end else
        Result := 'Unknown';
    end;

    (takes 16 ms and works fine tyvm)

    And to find out were I am I do:

    Simba Code:
    Writeln(GetMyPos);

    And it outputs the correct spot

    BUT When ever I try to do this:

    Simba Code:
    if (GetMyPos = 'Alter') then secretprocedure;
     if (GetMyPos = 'Bank') then LocateBank;

    If im at the alter it will do secret procedure, but if i'm at the bank it won't do locatebank (and yes it can find the bank)

    Any reason why I can't use the function returning a string for more then 1 if statements? Do I have to use a global variable?
    Also "Bank != bank"

    use (LowerCase(GetMyPos) = 'alter') ect

    Forum account issues? Please send me a PM

  5. #5
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Bank is capitalised.

  6. #6
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Justin View Post
    Also "Bank != bank"

    use (LowerCase(GetMyPos) = 'alter') ect
    Ahh gotcha. I thought pascal wasn't case sensitive (I guess thats just vars and procedures/functions?)

    It was my fault for having inconsistent practices anyway

  7. #7
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    Ahh gotcha. I thought pascal wasn't case sensitive (I guess thats just vars and procedures/functions?)

    It was my fault for having inconsistent practices anyway

    Literals in no language is case insensitive. Keywords would be case insensitive in some languages but never literals.

    Literals include bytes/chars, strings, array of chars, char*, const char*, array of strings, etc..


    Why? Because ASCII.. that's why:

    A = 0x41 || 1000001
    a = 0x61 || 1100001


    Both completely different values. Notice that 1 bit that's changed? That's how you convert from upper to lowercase. Register sees that 1 bit set, it knows it's lowercase.
    Last edited by Brandon; 06-22-2013 at 04:03 AM.
    I am Ggzz..
    Hackintosher

  8. #8
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Literals in no language is case insensitive. Keywords would be case insensitive in some languages but never literals.

    Literals include bytes/chars, strings, array of chars, char*, const char*, array of strings, etc..


    Why? Because ASCII.. that's why:

    A = 0x41 || 1000001
    a = 0x61 || 1100001


    Both completely different values. Notice that 1 bit that's changed? That's how you convert from upper to lowercase. Register sees that 1 bit set, it knows it's lowercase.
    And that's why .equalsIgnoreCase() is my best friend

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •