Log in

View Full Version : Why the hell are these 2 procedures repeating?



rj
12-01-2012, 09:12 PM
In my script, the procedures walkbank and use bank repeat for some reason and its making me mad.

Heres what the script does:
withdraws raw fish
uses them on range
chooses cook all
waits for all the raw fish to disapear.
walks to the bank(clicking the bank minimap icon)
opens the bank
hits store all
clicks the minimap icon
opens the bank
clicks the minimap icon
opens the bank
clicks the minimap icon
opens the bank

so on and so on until i stop it..

Heres the script:
program Cook;
{$i srl/srl.simba}
const
rawfishcol=5927257;
cookrange=7633898;
cookfish=12868;
minimap=2216175;
bank=1857394;
bankx=305;
banky=61;
bankxtwo=404;
bankytwo=131;
var
cookall,usebank,cookicon: Integer;
procedure backpack;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,4578368,350,296,381,320,5) then
begin
MouseSpeed:=15;
mmouse(x, y,1,1);
Wait(250 + Random(150));
ClickMouse(X, Y, mouse_Left);
Wait(1200 + Random(900));
end;
end;
procedure bankfish;
var
X, Y: Integer;
begin
Writeln('Looking for bank . . .')
if FindColorTolerance(X,Y,bank,bankx,banky,bankxtwo,b ankytwo,5) then
begin
MouseSpeed:=15;
mmouse(x, y,1,1);
Writeln('Found bank.')
Wait(250 + Random(150));
ClickMouse(x, y, mouse_Right);
Wait(900 + Random(250));
FindBitmapToleranceIn(usebank, X, Y,31, 93, 455, 304, 165)
MouseSpeed:=40;
mmouse(x, y,1,1);
WriteLn('Opened Bank!');
Wait(500 + Random(120));
ClickMouse(X, Y, mouse_Left);
Wait(1500 + Random(250));
backpack;
end;
end;
procedure walkbank;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,minimap,555,85,630,122,5) then
begin
mmouse(x, y,1,1);
Wait(600 + Random(150));
ClickMouse(x, y, mouse_Left);
Wait(6500 + Random(1500));
bankfish;
end;
end;
procedure checkcook;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,rawfishcol,566,217,715,454, 5) then
begin
Wait(600 + Random(150));
checkcook;
end;
walkbank;
end;
procedure choosefish;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,cookfish,207,379,300,452,5) then
begin
MouseSpeed:=17;
mmouse(x, y,1,1);
Wait(600 + Random(150));
ClickMouse(x, y, mouse_Right);
Wait(800 + Random(150));
FindBitmapToleranceIn(cookall, X, Y,194, 351, 311, 478, 155)
mmouse(x, y,1,1);
Wait(600 + Random(150));
ClickMouse(x, y, mouse_Left);
checkcook;
end;
end;
procedure cookfisha;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,cookrange,374,12,503,121,5) then
begin
if FindColorTolerance(X,Y,rawfishcol,558,218,718,455, 5) then
begin
MouseSpeed:=17;
mmouse(x, y,1,1);
Wait(600 + Random(150));
ClickMouse(x, y, mouse_Left);
Wait(600 + Random(150));
if FindColorTolerance(X,Y,cookrange,374,12,503,121,5) then
begin
mmouse(x, y,1,1);
Wait(600 + Random(150));
ClickMouse(x, y, mouse_Left);
Wait(7800 + Random(150));
choosefish;
end;
end;
end;
end;
procedure closecook;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,8421504,423,29,491,45,15) then
begin
Wait(800 + Random(150));
Writeln('Closing bank . . .')
MouseSpeed:=20;
mmouse(x, y,1,1);
Wait(250 + Random(150));
ClickMouse(x, y, mouse_Left);
Wait(700 + Random(150));
cookfisha;
end;
end;
procedure withdrawfish;
var
X, Y: Integer;
begin
if FindColorTolerance(X,Y,rawfishcol,261,124,389,235, 5) then
begin
MouseSpeed:=15;
mmouse(x, y,1,1);
Wait(350 + Random(150));
ClickMouse(x, y, mouse_Right);
MouseSpeed:=10;
Wait(750 + Random(150));
mmouse(x, y+65,1,1);
ClickMouse(x, y, mouse_Left);
closecook;
end;
end;
begin
cookall := BitmapFromString(21, 15, 'meJyTUdeWGVA0dccxICJSGaZKiC' +
'ADAwNBvUA1mCYQ1A5XAFGDZgLx2vFzcQUC3NfICE07mgtxOR5 uC6Z' +
'2rHqJdDye6KOK3wlqx5WE8GsHImRfYw0BNEFcoURnBAAo+e/w');
usebank := BitmapFromString(38, 13, 'meJyTUdeWoTuauuMYEOHiko3+/2' +
'dARpg2MjAwYOVSaCMEoFlKaxvR2IPQRggXjtBCBk+ko8UjBBC 0Ec5' +
'GBmjiuCwlOx7xeBDNdirGI6Zf0IIaOcSIsVEGKQ8iG4JmAv7Q Jinl' +
'4HI2fr/gSlHEpBy00ENzNlZBglJEKqAPAgANRYUm');
cookicon := BitmapFromString(9, 11, 'meJw7cICaQPDfP2HrFAiSjV4DJOH' +
'iTH/+MDIwICNeJWseRT+gOBBBFAMRUASIIFJANQx372JKLQADoCxW' +
'KYiNaFIQLXB3LkACRHoNAJkkmKw=');
repeat
withdrawfish;
until False;
FreeBitmap(cookall);
FreeBitmap(usebank);
FreeBitmap(cookicon);
end.

CRASH_OVERRIDE
12-01-2012, 10:43 PM
you have at the bottom:


Repeat
withdrawfish
Until(False);



So it is going to keep withdrawing from the bank over and over forever!.

Change it to something like:

Repeat
withdrawfish
Until(InvFull) Or Not(InvEmpty);


This way its going to keep repeating Withdrawall until your inventory is either full or your inventory is not empty. This way if your down to the last set of fish it will withdraw fro example the last 7 fish and cook them whereas without it, its going to stop before cooking all the fish.

I could be wrong i have only been learning simba for a week and a bit.

rj
12-01-2012, 10:57 PM
you have at the bottom:


Repeat
withdrawfish
Until(False);



So it is going to keep withdrawing from the bank over and over forever!.

Change it to something like:

Repeat
withdrawfish
Until(InvFull) Or Not(InvEmpty);


This way its going to keep repeating Withdrawall until your inventory is either full or your inventory is not empty. This way if your down to the last set of fish it will withdraw fro example the last 7 fish and cook them whereas without it, its going to stop before cooking all the fish.

I could be wrong i have only been learning simba for a week and a bit.

If you read the script your would know that "withdrawfish" is a procedure, and if you read the thread you would know it's not constantly withdrawing fish.

CRASH_OVERRIDE
12-02-2012, 12:11 AM
Well if you know everything then why even post with an issue im only trying to help and as i said i am new....

Zyt3x
12-02-2012, 12:19 AM
First thing I do when debugging scripts is to look through all my code; whenever I have problems following my own code I try to reorganize it so that I can follow it better.
I see that your procedures all call another procedure, why not try to put the procedures into the mainloop instead?

so instead of going
Repeat
withdrawfish
Until(False);

try this instead;
Repeat
withdrawfish
closecook;
cookfisha;
/// ... and so on
Until(False);

A thumb rule of procedures is that they execute one step each so that you can call that procedure whenever you want to execute that step soely, and not all the other procedures (like as if the player started at the cooking range instead of in the bank then it would have to cook the food first and then walk to the bank -> repeat)

You'll get there quickly, just keep on trying :) It's not an easy task to master scripting, but absolutely worth it

rj
12-02-2012, 12:28 AM
First thing I do when debugging scripts is to look through all my code; whenever I have problems following my own code I try to reorganize it so that I can follow it better.
I see that your procedures all call another procedure, why not try to put the procedures into the mainloop instead?

so instead of going
Repeat
withdrawfish
Until(False);

try this instead;
Repeat
withdrawfish
closecook;
cookfisha;
/// ... and so on
Until(False);

A thumb rule of procedures is that they execute one step each so that you can call that procedure whenever you want to execute that step soely, and not all the other procedures (like as if the player started at the cooking range instead of in the bank then it would have to cook the food first and then walk to the bank -> repeat)

You'll get there quickly, just keep on trying :) It's not an easy task to master scripting, but absolutely worth it



I'll see how that works out

EDIT:
repeat
withdrawfish;
closecook;
cookfisha;
choosefish;
checkcook;
walkbank;
bankfish;
backpack;
until (IsKeyDown (114));
FreeBitmap(cookall);
FreeBitmap(usebank);
// FreeBitmap(cookicon);
end.
It still kept looping the procedures


walkbank;
bankfish;
backpack;

Zyt3x
12-02-2012, 12:39 AM
Try finding out exactly where it is repeating by putting in small WriteLn's everywhere in order to figure out exactly what is going on. i.e try putting some right before and after a FindColorTolerance call; WriteLn('backpack'); in the start of the backpack procedure and WriteLn('backpack; FindColorTolerance: foundcolor'); after the "if findcolortolerance() then begin" part of the procedure

rj
12-02-2012, 12:51 AM
Try finding out exactly where it is repeating by putting in small WriteLn's everywhere in order to figure out exactly what is going on. i.e try putting some right before and after a FindColorTolerance call; WriteLn('backpack'); in the start of the backpack procedure and WriteLn('backpack; FindColorTolerance: foundcolor'); after the "if findcolortolerance() then begin" part of the procedure

It's repeating the minimap procedure.