Results 1 to 4 of 4

Thread: If... Then... Else..., What am I going wrong?

  1. #1
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default If... Then... Else..., What am I going wrong?

    Hey,

    so I always thought if...then...else works like this:
    If the condition from if is met, then the code under "then" is executed and not what is included in else.
    The "else"-code is only executed when the condition is not met.



    Doesn't seem to work that way.
    Here is a procedure I wrote; note the underlined part, this seems to be the one that is causing trouble:

    Code:
    Procedure OpenGate;
    
    var
        x, y: Integer;
    begin
    
    if FindObjCustom(x, y, ['Open Gate'], [3622483, 3094077], 3)
    
    then
      begin
      Writeln('Gate found. Clicking.');
      ClickMouse(x, y, mouse_Left);
      Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
      Wait(12000);
      end
    
    else Writeln('Gate not found, is it already open? Checking...');
     
     if FindObjCustom(x, y, ['Close Gate'], [3622483, 3094077], 3)
     then begin Writeln('Gate is already open! Continuing with walking.')
              end
    
    else
    Writeln('Something might have gone wrong, no gate in sight, neither open or closed. Teleporting back to Burthorpe.');
    LodestoneTeleport('Burthorpe');
    end;
    Now what I want to happen is that after the gate gets opened or the gate is already open, the rest of the code is skipped with and the procedure ends.
    What actually happens is that, no matter what the result of the door opening was the failsafe fires...

    Using the "Exit;" command I was able to work around the problem for a while but since I reprogrammed the code this is not longer possible, except with labels which you shouldn't use unless it's really necessary, so I need to get this done properly.

    Could someone point out my error? Thanks a lot Villavu!

  2. #2
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    The then should be ath the end of the if line, and if you want something with multiple lines to be executed you need them to be between begins and ends.

    Simba Code:
    Procedure OpenGate;
    var
        x, y: Integer;
    begin
      if FindObjCustom(x, y, ['Open Gate'], [3622483, 3094077], 3) then
      begin
        Writeln('Gate found. Clicking.');
        ClickMouse(x, y, mouse_Left);
        Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
        Wait(12000);
      end else
        Writeln('Gate not found, is it already open? Checking...');
      if FindObjCustom(x, y, ['Close Gate'], [3622483, 3094077], 3) then
      begin
        Writeln('Gate is already open! Continuing with walking.')
      end else
      begin
       Writeln('Something might have gone wrong, no gate in sight, neither open or closed. Teleporting back to Burthorpe.');
       LodestoneTeleport('Burthorpe');
      end;
    end;

    I suggest reading through this if you haven't already: http://villavu.com/forum/showthread.php?t=58935

  3. #3
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    I'm assuming you want the break; command, which 'breaks' out of the current loop and continues with the rest of the code. The tut BMW posted is really nicely written as well if you're looking for some further explanation.

  4. #4
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    BMWxi, thanks a lot, stuff seems to work now

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
  •