Results 1 to 7 of 7

Thread: Stupid bug?

  1. #1
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default Stupid bug?

    This is my function and for some reason it wont execute all the functions i pass to it. It just gives me an error even though it shouldn't.
    Simba Code:
    program new;
    {$i SRL/SRL.scar}

    function printa: boolean;
    begin
      writeln('a');
      Result:= True;
    end;

    function printb: boolean;
    begin
      writeln('b');
      Result:= True;
    end;

    function printc: boolean;
    begin
      writeln('c');
      Result:= True;
    end;

    function StepFuncs(Functions: Array of String; Conditions: Array of Boolean): Boolean;
    {will progress through the list of Functions with no parameters if Condition is met eg:
      if this then
        if that then
          if thisandthat then
            blahblahblah
     Also, if Conditions are the same then just use it once in an array eg:
       StepFuncs(['func1', 'func2', 'func3'], [True]) is the same as
       StepFuncs(['func1', 'func2', 'func3'], [True, True, True])
    }

    var
      a, b: Integer;
      c: TVariantArray;
      bool: boolean;
    begin
      b:= High(Functions);
      if Length(Functions) <> Length(Conditions) then
      begin
        SetLength(Conditions, b + 1);
        for a:= 1 to b do
          Conditions[a]:= Conditions[0];
      end;
      for a:= 0 to b do
      begin
        bool:= CallProc(Functions[a], c);
        if bool <> Conditions[a] then       //<------------------here is the error!
        begin
          writeln('An error has occured while trying to execute:' + Functions[a]);
          break;
        end;
      end;
    end;

    procedure MainLoop;
    begin
      StepFuncs(['printa', 'printb', 'printc'], [True]);
    end;

    begin
      MainLoop;
    end.

  2. #2
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    I see that you callproc functions but its not a procedure ... Correct me if im wrong.
    "Logic never changes, just the syntax" - Kyle Undefined?

    Remember, The Edit Button Is There For A Reason!!!

  3. #3
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Yago View Post
    I see that you callproc functions but its not a procedure ... Correct me if im wrong.
    It doesn't matter if its a function or a procedure, it still works.

  4. #4
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Yago View Post
    I see that you callproc functions but its not a procedure ... Correct me if im wrong.
    CallProc is a function, it's part of Simba.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    program new;
    {$i SRL\SRL.scar}

    function printa: boolean;
    begin
      writeln('a');
      Result:= True;
    end;

    function printb: boolean;
    begin
      writeln('b');
      Result:= True;
    end;

    function printc: boolean;
    begin
      writeln('c');
      Result:= True;
    end;

    function StepFuncs(Functions: Array of String; Conditions: Array of Boolean): Boolean;
    {will progress through the list of Functions with no parameters if Condition is met eg:
      if this then
        if that then
          if thisandthat then
            blahblahblah
     Also, if Conditions are the same then just use it once in an array eg:
       StepFuncs(['func1', 'func2', 'func3'], [True]) is the same as
       StepFuncs(['func1', 'func2', 'func3'], [True, True, True])
    }

    var
      a, b: Integer;
      c: TVariantArray;
      bool: boolean;
    begin
      b:= High(Functions);
      if Length(Functions) <> Length(Conditions) then
      begin
        SetLength(Conditions, b + 1);
        for a:= 1 to b do
          Conditions[a]:= Conditions[0];
      end;
      for a:= 0 to b do
      begin
        if CallProc(Functions[a], c) <> Conditions[a] then       //<------------------here is the error!
        begin
          writeln('An error has occured while trying to execute:' + Functions[a]);
          break;
        end;
      end;
    end;

    procedure MainLoop;
    begin
      StepFuncs(['printa', 'printb', 'printc'], [True]);
    end;

    begin
      MainLoop;
    end.
    ?
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    ^ Thats what i did to fix it up, but I want to know why it wont work.

  7. #7
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    program new;
    {$i SRL/SRL.scar}

    function printa: boolean;
    begin
      writeln('a');
      Result:= True;
    end;

    function printb: boolean;
    begin
      writeln('b');
      Result:= False;
    end;

    function printc: boolean;
    begin
      writeln('c');
      Result:= True;
    end;

    function StepFuncs(Functions: Array of String; Conditions: Array of Boolean): Boolean;
    {will progress through the list of Functions with no parameters if Condition is met eg:
      if this then
        if that then
          if thisandthat then
            blahblahblah
     Also, if Conditions are the same then just use it once in an array eg:
       StepFuncs(['func1', 'func2', 'func3'], [True]) is the same as
       StepFuncs(['func1', 'func2', 'func3'], [True, True, True])
    }

    var
      a, b: Integer;
      c: TVariantArray;
      bool: boolean;
    begin
      b:= High(Functions);
      if Length(Functions) <> Length(Conditions) then
      begin
        SetLength(Conditions, b + 1);
        for a:= 1 to b do
          Conditions[a]:= Conditions[0];
      end;
      for a:= 0 to b do
      begin
        bool:= CallProc(Functions[a], c);
        if (not bool) = Conditions[a] then       //<------------------here is the error!
        begin
          writeln('An error has occured while trying to execute:' + Functions[a]);
          break;
        end;
      end;
    end;

    procedure MainLoop;
    begin
      StepFuncs(['printa', 'printb', 'printc'], [True, False, True]);
    end;

    begin
      MainLoop;
    end.
    Seems to be working the way it is supposed to .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

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
  •