SRL Archive - OSR Help

Stupid bug?


KingKong

2011-04-01 23:45:38

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.
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.

Yago

2011-04-01 23:58:38

I see that you callproc functions but its not a procedure … Correct me if im wrong.

KingKong

2011-04-02 00:05:33

From: Yago
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.

Dgby714

2011-04-02 00:05:36

From: Yago
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.

Sex

2011-04-02 00:47:09

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.
?:D

KingKong

2011-04-02 00:56:00

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

Sex

2011-04-03 04:07:31

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 :p.