I decided to make a quick and easy general debugging function that (at the moment) returns the begins, end, repeats and untils in a script as an integer in an array (with begin 0, end 1, repeat 2 and until 3). Also, it includes ReplaceRegex2, which, as far as I know, works in the same way replace regex, except it returns how many times it replaced something (in the variable count).
ReplaceRegex2:
SCAR Code:
function ReplaceRegex2(Txt,Regex,ReplaceStr: string; var count: integer): string;
var
RPos,RLen: integer;
begin
repeat
RLen:= Length(Regex);
RPos:= RegexPos(Txt,Regex);
if(RPos = -1) then
Break;
Delete(Txt,Rpos,RLen-1);
Insert(ReplaceStr,Txt,RPos);
Inc(Count);
until(count >= 1000);
Result:= Txt;
end;
Debug:
SCAR Code:
function Debug(fileloc: string; var output: array of integer):Boolean;
var
iFile: Integer;
sFile: String;
begin
SetArrayLength(output,4);
iFile:= OpenFile(fileloc,false);
ReadFileString(iFile,sFile,filesize(iFile));
CloseFile(iFile);
sFile:= Lowercase(sFile);
ReplaceRegex2(sFile,'begin','<egi>',Output[0]);
ReplaceRegex2(sFile,'end','<n>',Output[1]);
ReplaceRegex2(sFile,'repeat','<epea>',Output[2]);
ReplaceRegex2(sFile,'until','<nti>',Output[3]);
end;
You would use replaceregex2 the exact same way, excpet you put an integer to store the replaces in.
E.g.
SCAR Code:
Writeln(ReplaceRegex2('Moo Quack Cluck','Moo','Quack',Moos)+' and '+IntToStr(Moos)+' moo/s');
would give you: 'Quack Quack Cluck and 1 moo/s' in the debug log.
Debug would be used as:
SCAR Code:
Debug(ScriptPath+'newscript.scar',debugArray);
Writeln('You have '+IntToStr(debugArray[0])+' begin/s');
or
SCAR Code:
Writeln('You have '+IntToStr(debugArray[1]-debugArray[0])+' more end/s than begins';
That should explain the general idea of them. If you have any question, feel free to ask.