Results 1 to 7 of 7

Thread: This function always returns false, any help?

  1. #1
    Join Date
    Jun 2016
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Question This function always returns false, any help?

    Code:
    function isInZone3(): boolean;
    var
      myTile, tile1: TTile;
    begin
      tile1 := Point(3228,9899);
      myTile := Reflect.Tiles.GetGlobalTile();
        write( 'x coord is ' ); write(myTile.X );write('  looking for ');writeln(tile1.X);
        write( 'y coord is ' ); write(myTile.Y );write('  looking for ');writeln(tile1.Y);
      if(myTile.X = tile1.X AND myTile.Y = tile1.Y) then
      begin
        result:= True;
        //Exit;
      end else
      begin
        result:=false;
      end;
    end;
    when I do
    Code:
    writeln(isInZone3());
    I get
    Code:
    x coord is 3228  looking for 3228
    y coord is 9899  looking for 9899
    False
    even though the function should be returning true

  2. #2
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

  3. #3
    Join Date
    Jun 2016
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks a lot fam

  4. #4
    Join Date
    Apr 2016
    Location
    New Zealand
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    32 Post(s)

    Default

    Here's a function to check if the player is within an area.

    Simba Code:
    function PlayerInArea(x1, y1, x2, y2: Integer): boolean;
    var
      Area := IntToBox(x1, y1, x2, y2);
      MyCurrentTile: TPoint;
    begin
      MyCurrentTile := Reflect.Tiles.GetGlobalTile();
      Result := PointInBox(MyCurrentTile, Area);
    end;

    You can also condense your Write functions using '+'.

    Simba Code:
    Writeln('Exp gained: ' + toStr(xpGained) + ' (' + (toStr(xpHour)) + ' p/hr)');

  5. #5
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Quote Originally Posted by Dissimulo View Post
    Here's a function to check if the player is within an area.

    Simba Code:
    function PlayerInArea(x1, y1, x2, y2: Integer): boolean;
    var
      Area := IntToBox(x1, y1, x2, y2);
      MyCurrentTile: TPoint;
    begin
      MyCurrentTile := Reflect.Tiles.GetGlobalTile();
      Result := PointInBox(MyCurrentTile, Area);
    end;

    You can also condense your Write functions using '+'.

    Simba Code:
    Writeln('Exp gained: ' + toStr(xpGained) + ' (' + (toStr(xpHour)) + ' p/hr)');
    Also, you can simply use the multiparam feature of writeln (if using lape, so always).
    Simba Code:
    Writeln('Exp gained: ', xpGained, ' (', xpHour, ' p/hr)');

    And, as the issue has already been covered, its really just being boolean evaluated left to right, except that and has first dibs in order.

    so
    5 = 5 and 10 = 10
    5 = SOMEINT = 10
    false = 10
    false

    or, ((5 = (5 and 10)) = 10)

  6. #6
    Join Date
    Jun 2013
    Location
    Scranton
    Posts
    496
    Mentioned
    5 Post(s)
    Quoted
    220 Post(s)

    Default

    Simba Code:
    function isInZone3(): boolean;
    var
      myTile, tile1: TTile;
    begin
      tile1 := Point(3228,9899);
      myTile := Reflect.Tiles.GetGlobalTile();
        write( 'x coord is ' ); write(myTile.X );write('  looking for ');writeln(tile1.X);
        write( 'y coord is ' ); write(myTile.Y );write('  looking for ');writeln(tile1.Y);
      if (myTile.X = tile1.X) then
      if (myTile.Y = tile1.Y) then
      begin
        result:= True;
        //Exit;
      end else
      begin
        result:=false;
      end;
    end;
    I think this would work

  7. #7
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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