Results 1 to 6 of 6

Thread: Efficiency with if-else

  1. #1
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default Efficiency with if-else

    Hey, I am coding a nmz script that I'll be releasing to the public. I currently have this procedure:

    Simba Code:
    procedure drinkpray;
    begin
    if finddtm(pray1,x,y,mix1,miy1,mix2,miy2) then begin
        mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true);
        end else if finddtm(pray2,x,y,mix1,miy1,mix2,miy2) then begin
          mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true);
          end else if finddtm(pray3,x,y,mix1,miy1,mix2,miy2) then begin
            mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true);
            end else if finddtm(pray4,x,y,mix1,miy1,mix2,miy2) then begin
              mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true);
            end else if findcolortolerance(10933076,x,y,744,488,904,738,3) then begin
              mmouse(x,y,1,1);
              wait(133+random(222));
              if isuptext('rink') then clickmouse2(mouse_left);
            end else writeln('no more pray');
    end;

    It's functional but there's gotta be a better way to do this. Anyone able to show me how?

  2. #2
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by purerange86 View Post
    It's functional but there's gotta be a better way to do this. Anyone able to show me how?
    Ok so firstly you don't need a begin and end if only one statement follows the 'then'


    Simba Code:
    if isUpText('hello') then
      writeLn('hi');
    Simba Code:
    if isUpText('hello') then
    begin
      writeLn('hi');
      writeLn('hey');
    end;

    Simba Code:
    procedure drinkpray;
    begin

      if finddtm(pray1,x,y,mix1,miy1,mix2,miy2) then
        mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true)
      else
        if finddtm(pray2,x,y,mix1,miy1,mix2,miy2) then
          mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true)
        else
          if finddtm(pray3,x,y,mix1,miy1,mix2,miy2) then
            mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true)
          else
            if finddtm(pray4,x,y,mix1,miy1,mix2,miy2) then
              mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true)
            else
              if findcolortolerance(10933076,x,y,744,488,904,738,3) then
              begin
                mmouse(x,y,1,1);
                wait(133+random(222));
                if isuptext('rink') then
                  clickmouse2(mouse_left);
              end else
                writeln('no more pray');
    end;

    E:

    I guess if you didn't want a particular order you could just use or:

    Simba Code:
    procedure drinkpray;
    begin

      if finddtm(pray1,x,y,mix1,miy1,mix2,miy2) or
         finddtm(pray2,x,y,mix1,miy1,mix2,miy2) or
         finddtm(pray3,x,y,mix1,miy1,mix2,miy2) or
         finddtm(pray4,x,y,mix1,miy1,mix2,miy2) then
        mouse(x+randomrange(-4,4),y+randomrange(-8,3),1,1,true)
      else
        if findcolortolerance(10933076,x,y,744,488,904,738,3) then
        begin
          mmouse(x,y,1,1);
          wait(133+random(222));
          if isuptext('rink') then
            clickmouse2(mouse_left);
        end else
          writeln('no more pray');
    end;
    Last edited by The Mayor; 01-20-2014 at 09:49 PM.

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

    Default

    Simba Code:
    procedure drinkprayer;
    var
      I, X, Y: Integer;
    begin
      for I := 0 To High(Dtms) do
        if (Not FindDTM(Dtms[i] , X, Y, MIX1, MIY1, MIX2, MIY2)) then
        begin
          if (FindColorTolerance(10933076, X, Y, 744, 488, 904, 738, 3)) then
          begin
            MMouse(x,y,1,1);
            Wait(133 + Random(222));
            if IsUptext('rink') then
              ClickMouse2(MOUSE_LEFT);
            Exit;
          end;
        end else
          break;

      Mouse(X + RandomRange(-4,4), Y + RandomRange(-8,3), 1, 1, True);
    end;
    Last edited by Brandon; 01-20-2014 at 10:04 PM.
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Simba Code:
    procedure drinkprayer;
    var
      I, X, Y: Integer;
    begin
      for I := 0 To High(Dtms) do
        if (Not FindDTM(Dtms[i] , X, Y, MIX1, MIY1, MIX2, MIY2)) then
        begin
          if (FindColorTolerance(10933076, X, Y, 744, 488, 904, 738, 3)) then
          begin
            MMouse(x,y,1,1);
            Wait(133 + Random(222));
            if IsUptext('rink') then
              ClickMouse2(MOUSE_LEFT);
            Exit;
          end;
        end else
          break;

      Mouse(X + RandomRange(-4,4), Y + RandomRange(-8,3), 1, 1, True);
    end;
    Many thanks to both of you for all the help!

    Brandon, this looks awesome, and is really helpful--thanks for putting the time into this. I didn't realize that you could use a if-not thing to define your variables, which I found really cool.
    I'm unclear about a few things though. what does high(dtms) return? Do I need to define an array of dtms? Lastly what does "break" do?
    Sorry, I'm a noob I know. I'm looking at a loops tut but I'm still not completely sure whats going on
    Last edited by purerange86; 01-22-2014 at 02:43 AM.

  5. #5
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by purerange86 View Post
    Many thanks to both of you for all the help!

    Brandon, this looks awesome, and is really helpful--thanks for putting the time into this. I didn't realize that you could use a if-not thing to define your variables, which I found really cool.
    I'm unclear about a few things though. what does high(dtms) return? Do I need to define an array of dtms? Lastly what does "break" do?
    Sorry, I'm a noob I know. I'm looking at a loops tut but I'm still not completely sure whats going on
    for ... to ... do loops are a little bit more complicated that if .. then .. else statements

    high() just returns the highest number in an array, in this case the highest number in the DTM array. e.g. [dtm1, dtm2, dtm3, dtm4] would return 3, as arrays start at 0 (0, 1, 2, 3).

    Simba Code:
    for I := 0 To High(Dtms) do

    is basically

    Simba Code:
    for I := 0 To 3 do

    The break means it will break out of the loop, and continue with the rest of the procedure (which in this case is just the mouse() statement). If it does find any of the DTMs in the array it will break out of the loop and move the mouse to it and click. To use this you would obviously have to put all your DTMs into an array when you start up the script.

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

    Default

    Quote Originally Posted by purerange86 View Post
    Many thanks to both of you for all the help!

    Brandon, this looks awesome, and is really helpful--thanks for putting the time into this. I didn't realize that you could use a if-not thing to define your variables, which I found really cool.
    I'm unclear about a few things though. what does high(dtms) return? Do I need to define an array of dtms? Lastly what does "break" do?
    Sorry, I'm a noob I know. I'm looking at a loops tut but I'm still not completely sure whats going on
    DTMs is an array of DTM's and High returns the (length - 1).

    Break exits the loop but not the function. "Breaks" out of the loop. The reason I found it more efficient is because it is easier to just create an array of DTM's and have the loop find DTMs[I].. Rather than "Find DTM1, FindDTM2, FindDTM3, etc..".


    Up to you though.
    I am Ggzz..
    Hackintosher

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
  •