SRL Archive - OSR Help

Small logic problem


cause

2011-12-25 17:23:34

Hi guys, just working on my first real script (I think I released something dumb and small years ago), a crafting guild miner. An important part of the script is that is changes location when all the silver is mined, or the gold is mined, to the other end of the mine in the guild and continues to mine there. My problem is that it currently only mines gold, and once it can't find any gold, it relocates to the silver end of the guild successfully but it won't attempt mining. Here's the code:

program craftyminer;
{$DEFINE SMART}
{$i srl/srl.scar}
{$i sps/sps.simba}
{$i ObjectDTM\ObjDTMInclude.simba}
const
GOLDCOLOUR = 5296637;
SILVERCOLOUR = 15593208;
var
miningcolour, location: Integer;


procedure DeclarePlayers;
begin
HowManyPlayers:= 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := 'sdfg';
Players[0].Pass := 'asdf';
Players[0].Nick := '337';
Players[0].Pin := '';
Players[0].Active := true;
end;

Function ChatCheck(s: string): Boolean;
var
i, l : Integer;
b : Boolean;
begin
if (Pos(s, GetBlackChatMessage) > 0)then
begin
Writeln('Checked Black Chat Message');
Result:=True;
end;
end;

Function MineOre: boolean;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
if(FindColorSpiralTolerance(x, y, miningcolour, MSX1, MSY1, MSX2, MSY2, 30)) then
begin
writeln('Attempting to mine');
MMouse(x,y, 1,1);
Wait(750 + Random(100));
if isuptextex('ine') then
begin
Mouse(x, y, 1, 1, True);
wait(500 + random(250));
if (ChatCheck('swing your pick')) then
result := true;
Writeln('clicked')
wait(6000+random(1000));
Result := true;
end else
Writeln('Couldn''t find the rocks to mine');
end else
Writeln('Couldn''t find the rocks to mine');
end;

Procedure LocateSilver;
begin
if ObjDTMWalk('625:81:3:1:7:643:86:1:7:618:54:1:7:639:106', 0, 100, 80, True) then
begin
wait(500 + random(250));
MakeCompass('n');
WriteLn('location is now silver')
end
else WriteLn('could not locate silver');
end;

Procedure LocateGold;
begin
if ObjDTMWalk('630:121:3:1:7:653:124:1:7:622:143:1:7:646:100', 0, 100, 80, True) then
begin
wait(500 + random(250));
MakeCompass('s');
WriteLn('location is now gold')
end
else WriteLn('could not locate gold');
end;

Procedure ChangeLocation;
begin
if (location=0) then
begin
LocateSilver;
location := 1;
miningcolour := SILVERCOLOUR;
wait(500 + random(250));
end;
if (location=1) then
begin
LocateGold;
location := 0;
miningcolour := GOLDCOLOUR;
wait(500 + random(250));
end
else
WriteLn('location wasn''t valid');
end;

procedure mining;
begin
miningcolour := GOLDCOLOUR;
location := 0;
repeat
if not MineOre then
begin
ChangeLocation;
wait(500 + random(250));
end
else
WriteLn('something went wrong in proc mining');
until(InvFull);
end;

begin
smart_server := 1;
smart_members := false;
smart_signed := true;
smart_superDetail := false;
clearDebug();
setupSRL();
DeclarePlayers;
if not LoggedIn then LogInPlayer;
ObjDTM_Setup;
SetAngle(true);
repeat
mining;
//walktobank;
//bank;
//walktoguild;
//enterguild;
//gotorocks;
until(Players[CurrentPlayer].Active=false);
end.

And here is the debug after successfully mining a few gold ores:
Attempting to mine
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Attempting to mine
clicked
something went wrong in proc mining
Attempting to mine
Checked Black Chat Message
clicked
something went wrong in proc mining
Couldn't find the rocks to mine
Found Object DTM, walking.
Flag distance reached.
location is now silver
Found Object DTM, walking.

Any ideas on what's going on here?

cause

2011-12-25 23:07:23

Procedure ChangeLocation;
begin
if (location=0) then
begin
LocateSilver;
location := 1;
miningcolour := SILVERCOLOUR;
wait(500 + random(250));
Exit; //Needed to put this exit in
end;
if (location=1) then
begin
LocateGold;
location := 0;
miningcolour := GOLDCOLOUR;
wait(500 + random(250));
end
else
WriteLn('location wasn''t valid');
end;

I found my problem, I changed the location to 1, then it would perform the next if statement because location now =1 lol, my bad.