SRL Archive - OSR Help

Making This A Procedure With Variables...


SomeGuyFromHere

2013-03-15 16:20:41

Yeah, sorry for the cryptic title, but I don't quite know how to call this.
In my quest solving script I have to talk to a guy several times. Since the routine has to check if the right NPC was clicked, so click certain boxes that need to be clicked everytime etc. and needs to include a boolean variable for failsafes, its pretty long:

if FindColor(x, y, 1336122, 290, 467, 290, 467) then
begin
Writeln('Dialogue opened successfully. Is it the right guy? Checking...');

MouseBox(227, 463, 292, 473, 1);
Wait(3000+(Random(6000)));

RightGuy1:= DTMFromString('mwQAAAHic42RgYFgLxduA+DAQnwfiX0AcwsjAEAbEOkB8D4ifAvEjIH4GxA+A+DFU7D4Q3wXiEydOEMSsQHMJYUYiMBwAAFSJIsU=');
if FindDTM(RightGuy1, x, y, 0, 394, 516, 502) then

begin
Writeln('Yup, that is the right guy. Continuing...');
[B]Questguystep1success[/B]:=True;
guystep1tries:= 10;
end else
begin
Writeln('Error, It was the wrong guy!');
SPS_WalkPath([B]LodestoneToSummoningGuy[/B]);
guystep1tries:= (guystep1tries + 1);
QuestGuyProblemSolver;
end;
end else
begin
Writeln('Error, Dialogue was not opened!!');
SPS_WalkPath([B]LodestoneToSummoningGuy[/B]);
guystep1tries:= (guystep1tries + 1);
QuestGuyProblemSolver;
end;

until (guystep1tries = 10);

// End "Check If Dialogue Is Opened And If It Is The Right Guy"

// Continuing With "Accept Quest"

if [B]Questguystep1success [/B]= True then
begin
Wait(3000+(Random(6000)));

QuestBox1 := DTMFromString('m1gAAAHic42JgYGBlZGBYC6Q3APFBIFYE8q2AWBuIQ6A4AIgfA/E9IH4KxA+g7AdQ/lMo/yEQnzhxgijMCrKbCMxIJEYAAEcdJDY=');
QuestBox1Alternative := DTMFromString('mrAAAAHic42BgYGBlZGBYywDBr4BYEch3BOIQIA4G4kdAfA+In0IxOvv2BPyYEGAkgGEAAGbKFdg=');

if FindDTM(QuestBox1, x, y, 160, 415, 350, 445) then
begin
Mouse (x,y,100,5, true);
FreeDTM(QuestBox1);
end else
begin
Writeln('Second try to click the right box to continue with / accept the quest. Maybe the mouse of hovering over it?');
if FindDTM(QuestBox1, x, y, 160, 415, 350, 445) then
begin
Mouse(x,y,100,5, true);
FreeDTM(QuestBox1);
FreeDTM(QuestBox1Alternative);
end else
begin
Writeln('Box coult not be found');
FreeDTM(QuestBox1);
FreeDTM(QuestBox1Alternative);
end;
end;

Note the variables I added in bolt. These don't remain static but are modified a bit each time the routine is used in a different place in the script.

Now in terms of functionality everything is working great but repeating this monsterpiece of code again and again and again makes the script messy and difficult to read. I'd like to make this into a separate procedure that can just be called in the main procedure, like so:
OpenDialogue(QuestGuySuccessStep1OrAnotherBooleanVariable, SomeSPSWalkpath);

I might have overlooked how to code your own procedures with variables but I just don't get how to do that. Might be a very noobish question, but could you help me out?

microsphere

2013-03-15 17:20:50

Those variables that change every time a function/procedure is used are called parameters. Check out this tutorial and let me know if you have any questions:

http://villavu.com/forum/showthread.php?t=59061

SomeGuyFromHere

2013-03-16 12:35:59

Well, that was easier than I hoped:
Procedure TalkToPikkupstix (var Success: Boolean; Path: TPointArray);

var GuyTries, x, y, RightGuy1: integer;

begin

repeat
if FindObjCustom(x, y, ['Pik', 'kup'], [8617341, 7299402], 13) then
begin
Writeln('Summoning quest guy found. Clicking in 5 - 10 seconds.');
Wait(5000+(Random(5000)));
Mouse(x, y, 0, 0, True);
Writeln('OK, clicked on the guy. Waiting for 8 - 18 seconds.');
Wait(8000 + (Random(10000)));
end else
begin
Writeln('Error!');
QuestGuyProblemSolver;
Success:= False;
guyTries:= (guyTries + 1);
end;

// End "Begin Chat With Quest Guy"

// Begin "Check If Dialogue Is Opened And If It Is The Right Guy"

if FindColor(x, y, 1336122, 290, 467, 290, 467) then
begin
Writeln('Dialogue opened successfully. Is it the right guy? Checking...');

ContinueDialogue;

RightGuy1:= DTMFromString('mwQAAAHic42RgYFgLxduA+DAQnwfiX0AcwsjAEAbEOkB8D4ifAvEjIH4GxA+A+DFU7D4Q3wXiEydOEMSsQHMJYUYiMBwAAFSJIsU=');
if FindDTM(RightGuy1, x, y, 0, 394, 516, 502) then

begin
Writeln('Yup, that is the right guy. Continuing...');
Success:=True;
guytries:= 10;
end else
begin
Writeln('Error, It was the wrong guy!');
SPS_WalkPath(Path);
guyTries:= (guyTries + 1);
QuestGuyProblemSolver;
end;
end else
begin
Writeln('Error, Dialogue was not opened!!');
SPS_WalkPath(Path);
guyTries:= (guyTries + 1);
QuestGuyProblemSolver;
end;

until (GuyTries = 10);
end;
+rep given, also thanks for reminding me that parameters are called… parameters :duh::)