View Full Version : [HELP] Weird script glitch
Ketan
09-05-2012, 07:06 AM
I made a simple method to find a NPC. I'm getting a slight problem. Sometimes, I get a bug that makes the bot do this procedure again and again even after the writeln('whatever...'); is passed in the debug.
That means when Exit; is called, it does the method again. It's random kind of... Sometimes it don't, but when it do so, it doesn't stop.
[NOTE]: I've replaced few stuff in code, just to make my script un-guess-able, I wanna keep it private.
procedure TalkToNPC;
var
X, Y : Integer;
begin
MakeCompass('N');
X:=MSCX;
Y:=MSCY;
if FindObjTPA(X, Y, 4604739, 13, 1, 4, 9, 20, ['some npc']) then
begin;
Writeln('Looking for some npc...');
GetMousePos(X, Y);
Mouse(X, Y, 5, 5, False);
while not (WaitOption('Talk-to', 300)) do TalkToNPC;
Writeln('We found the npc!');
wait(2000+random(500));
while (AreTalking()) do
begin
KeyDown(50);
clickContinue(true, true);
wait(500+random(500));
end;
wait(1000+random(1000));
if (FindChatBoxText('received message', 8, clBlack)) then
Writeln('whatever....');
Exit;
end;
end;
Help is appreciated.
YoHoJo
09-05-2012, 07:10 AM
Try removing the Writeln('Whatever') line.
And if then statement only applies to the line directly after it, and since you what a writeln and then an exit, the exit will happen no matter what. Get me?
Ketan
09-05-2012, 07:18 AM
I still don't get how would that work, since it should end procedure any way. Anyone wanna comment on this and help me please?
Le Jingle
09-05-2012, 07:23 AM
if (FindChatBoxText('received message', 8, clBlack)) then
Writeln('whatever....'); // if .. then, will only apply to the next line after it..
Exit; // This will be carried out regardless..
if (FindChatBoxText('received message', 8, clBlack)) then
begin // this begin .. end will allow for everything to be carried out with the outcome of the if .. then statement
Writeln('whatever....');
Exit;
end;
Hope that helps.
Edit ~ It looks like you may have some infinite loops, unneeded code in there too, not too fond of the FinbObjTPA either, but then again that's my personal opinion. I personally would add some condition checks in the while..do loops, some WaitFunc's, .. Nevertheless, looks like you are grasping an understanding of pascal script, keep up the good work!
Here's my revision.. Also note the begin; error, the line after you called FindObjTPA, that may have been your concerned flaw:
// turning this into a function will be more reliable in the main loop/scheme of your script.
//procedure TalkToNPC;
function TalkToNPC: Boolean; // a boolean is either true or false
var
X, Y : Integer;
begin
result := false; // since we haven't done anything, default = false. (Runaway)
if not loggedin then
exit; // always an easy, great failsafe to start a function out with. (Runaway)
MakeCompass('N');
// X:=MSCX;
// Y:=MSCY; we don't need these as they dont even sort the points from the desired MSCx/MSCy...
if FindObjTPA(x, y, 4604739, 13, 1, 4, 9, 20, ['some npc']) then
begin//; you ended the if then with that semi-colon...
Writeln('Looking for some npc...');
// GetMousePos(X, Y); we don't need this, as x and y already contain the needed values from FindObjTPA
Mouse(X, Y, 5, 5, mouse_right);
while not (WaitOption('Talk-to', 300)) do
TalkToNPC; // you loop back to this point, which doesn't do justice, again looping a custom function with a loop and removing undesired results, In my opinion is 100x more effective. Plus if the colors change, you may never find the NPC, looping potentially forever.
Writeln('We found the npc!');
wait(2000+random(500)); // if lag hit you, you could suffer here
while (AreTalking()) do
begin
KeyDown(50);
clickContinue(true, true);
wait(500+random(500));
end;
wait(1000+random(1000)); // more static waits, not the best here
if (FindChatBoxText('received message', 8, clBlack)) then
begin
writeln('whatever....');
result := true;
Exit;
end;
end;
end;
Also note: I don't know what your intended result or two of the procedures/functions are in that revision, so I could only do so much.
Ketan
09-05-2012, 07:30 AM
That doesn't matter, I want Exit carried out anyway. Problem is that there is actually no infinite loop added in there.
The worst possibility is that this line: while not (WaitOption('Talk-to', 300)) do TalkToNPC;
is the cause, which is not possible as it passes the writeln('whatever'); and then does the loop.
Ketan
09-05-2012, 04:44 PM
Bump! Still need help!
CephaXz
09-05-2012, 05:00 PM
I think this is the main culprit.
while not (WaitOption('Talk-to', 300)) do TalkToNPC;
It will keep doing TalkToNPC forever. When it doesn't get the option 'Talk-to', it start doing TalkToNPC again. Lets call this the second TalkToNpc. Assuming this time it finds the NPC and got the option and reached writeln('whatever..'), it will Exit out of the second TalkToNPC, not the first one. Then it will continue to this
Writeln('We found the npc!');
wait(2000+random(500));
But because of while not (WaitOption('Talk-to', 300)) do TalkToNPC;
It will not go on, because option is not found. And it will do TalkToNPC again.
Correct me if I'm wrong with this :p
Just simply wrote this out, but there are lots of better ways.
MarkTime(t);
repeat
if FindObjTPA(X, Y, 4604739, 13, 1, 4, 9, 20, ['some npc']) then
begin
Writeln('Looking for some npc...');
Mouse(X, Y, 5, 5, False);
if TimeFromMark(t) > 30000 then
begin
writeln('Cant find NPC');
TerminateScript;
end;
end;
until WaitOption('Talk-to', 1000);
footballjds
09-05-2012, 05:00 PM
That doesn't matter, I want Exit carried out anyway. Problem is that there is actually no infinite loop added in there.
The worst possibility is that this line: while not (WaitOption('Talk-to', 300)) do TalkToNPC;
is the cause, which is not possible as it passes the writeln('whatever'); and then does the loop.
while not (WaitOption('Talk-to', 300)) do TalkToNPC; is an infinite loop. If it is never able to WaitOption it will do talkToNPC over and over.
it will not writeln until AFTERWARDS.
if you want multiple lines in any form of loop you need to use begin/ends
for instance you could change you infinite loop to:
while not(WaitOption('Talk-to', 300)) do
begin
TalkToNPC;
Writeln('Just tried to chat with an NPC');
end;
your calling the function inside the function, that's where the loop is. regardless of weather it finds the option or not it will not drop the function straight away the compiler needs to continue executing lines of code in order so it will have to go from begin to end unless a exit is hit. To test/fix this just make the wait option check for a longer period of time?
Ketan
09-06-2012, 03:01 PM
Just simply wrote this out, but there are lots of better ways.
MarkTime(t);
repeat
if FindObjTPA(X, Y, 4604739, 13, 1, 4, 9, 20, ['some npc']) then
begin
Writeln('Looking for some npc...');
Mouse(X, Y, 5, 5, False);
if TimeFromMark(t) > 30000 then
begin
writeln('Cant find NPC');
TerminateScript;
end;
end;
until WaitOption('Talk-to', 1000);
I like that way actually. Thanks for that.
your calling the function inside the function, that's where the loop is. regardless of weather it finds the option or not it will not drop the function straight away the compiler needs to continue executing lines of code in order so it will have to go from begin to end unless a exit is hit. To test/fix this just make the wait option check for a longer period of time?
I think you're right. I'll follow what Cephaxz did.
Thanks guys.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.