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