SRL Archive - OSR Help

Ran into a brick wall...


Twinki

2014-02-27 14:01:18

So I've hit a brick wall…

program MasterStallThiever;
{$DEFINE SMART}
{$I RSPS/srlRSPS.Simba}
//-----------------------------------------------------------------\\
//-- MasterStallThiever --\\
//-- By RGS Anon --\\
//-----------------------------------------------------------------\\
Const
StallToSteal = 5;
(*
Valid options:
Crafting = 1
Food = 2
General = 3
Magic = 4
Scimitar = 5
*)
var
_server:_rsps_server;

CloseButton, DepositAllButton, StolenItems, MoneyMade:Integer;

procedure SetupEmulation
begin
_server.init(721, 'Rage-Scape');
ClearDebug();
smart.setParams('http://ragescapeclient.web44.net/ragescape.html','/', 765, 560, ['OpenGL32.dll']);
setUpSMART;
end;

Procedure MouseBoxHover(X1, Y1, X2, Y2: Integer);
Begin
MMouse(RandomRange(X1,X2),RandomRange(Y1,Y2),0,0);
Wait(RandomRange(37,50));
End;

// Progress Report \\
procedure ProgressReport;
begin
wait(500);
ClearDebug();
WriteLn('***************PROGRESS REPORT*************************************');
WriteLn('* Script has run for : '+ TimeRunning +'');
WriteLn('* You have stolen '+ IntToStr(StolenItems) +' items!');
WriteLn('* You have made '+ IntToStr(MoneyMade) +' GP');
WriteLn('*Inv Count* '+ IntToStr(inventory.count()));
WriteLn(inventory.full);
WriteLn('*******************************************************************');
end;

// Load DTM's \\
procedure LoadDTMs;
begin
CloseButton := DTMFromString('mggAAAHicY2NgYHBmYmCwB2IvKHYBYmsgvgeUuwbEN4D4CRA/ZYCI6ajJMxjrKDPw8/HCMYiPCzDiwBAAACNhCNQ=');
DepositAllButton := DTMFromString('mwQAAAHic42RgYDjPyMCwC4ivAvENIL4IxNug+CwQ7wfik0C8D4rPAPE1IL4AxIehYldA9MIMoGmMKFhUVBTO9nGzYGBlIAwYicBwAADAxhEL');
end;


// Free DTM's \\
procedure FreeAllDTMs;
begin
FreeDTM(DepositAllButton);
FreeDTM(CloseButton);
end;

procedure Bank
var
X, Y:Integer;
begin
if inventory.full then
begin
WriteLn('Banking...');
Wait(RandomRange(500, 1000));
MouseBoxHover(16, 140, 37, 147);
If _server.IsUpTextMulti([ 'oposit', 'box']) then
begin
ClickMouse2(Mouse_Left);
Wait(RandomRange(1000, 2000));
If FindDTM(DepositAllButton, X, Y, 0, 0, 514, 337) then
begin
MMouse(X, Y, 0, 0);
Wait(300);
ClickMouse2(True);
Wait(RandomRange(500, 1000));
If FindDTM(CloseButton, X, Y, 0, 0, 514, 337) then
MMouse(X, Y, 0, 0);
ClickMouse2(True);
Wait(RandomRange(1000, 2000));
if inventory.full = False then
ReturnToStall;
end;
end;
end;
end;


procedure CraftingStall
begin
end;

procedure FoodStall
begin
end;

procedure GeneralStall
begin
end;

procedure MagicStall
begin
end;

procedure ScimitarStall
var
X, Y:Integer;
begin
If StallToSteal = 5 then
begin
if inventory.full = False then
begin
ProgressReport;
Repeat
MouseBoxHover(253, 126, 269, 138);
If _server.IsUpTextMulti([ 'imitar', 'stall']) then
begin
ClickMouse2(Mouse_Left);
ProgressReport;
end;
Until inventory.count + 1;
inc(StolenItems);
Wait(RandomRange(50, 100));
ProgressReport;
WriteLn('Stolen a Scimy');
If inventory.full then
Bank;
end;
end;
end;


procedure ReturnToStall
begin
If StallToSteal = 1 then
begin
ProgressReport;
WriteLn('Walking back to Stall');
Wait(2000);
end;
If StallToSteal = 2 then
begin
ProgressReport;
WriteLn('Walking back to Stall');
Wait(2000);
end;
If StallToSteal = 3 then
begin
ProgressReport;
WriteLn('Walking back to Stall');
Wait(2000);
end;
If StallToSteal = 4 then
begin
ProgressReport;
WriteLn('Walking back to Stall');
Wait(2000);
end;
If StallToSteal = 5 then
begin
ProgressReport;
WriteLn('Walking back to Stall');
Wait(2000);
ProgressReport;
MouseBoxHover(484, 134, 501, 143);
If _server.IsUpTextMulti([ 'imitar', 'stall']) then
begin
ClickMouse2(Mouse_Left);
Wait(RandomRange(2000, 3000));
ProgressReport;

MouseBoxHover(253, 126, 269, 138);
If _server.IsUpTextMulti([ 'imitar', 'stall']) then
ScimitarStall;
end;
end;
end;



procedure DeclareStallsToSteal
begin
If StallToSteal = 1 then
CraftingStall;

If StallToSteal = 2 then
FoodStall;

If StallToSteal = 3 then
GeneralStall;

If StallToSteal = 4 then
MagicStall;

If StallToSteal = 5 then
ScimitarStall;
end;


begin
ClearDebug();
LoadDTMs;
AddOnTerminate('FreeAllDTMs');
SetupEmulation;
//Wait(30000);
Repeat
DeclareStallsToSteal;
ProgressReport;
Until IsKeyDown(113)
end.

In the Bank procedure, toward the end of it I need it to go back to the stall it was previously stealing at. So I've made a full procedure to do that, but the problem is that ReturnToStall needs to be below the Stall procedures (I only have Scimitar Stall coded ATM) since ReturnToStall calls the Stall procedures.

The problem is, I can't do anything because Bank needs to call ReturnToStall, but needs to be above the Stall procedures because the stall procedures need to call Bank. Hopefully that makes some sort of sense lol :duh:

Brandon

2014-02-27 14:16:38

From: Twinki
So I've hit a brick wall…



What you need to learn is what is known as a Forward Declarations: http://en.wikipedia.org/wiki/Forward_declaration


procedure meh; forward;

procedure foo;
begin
writeln('foo called');
meh;
end;

procedure meh;
begin
writeln('meh called');
foo;
end;

begin
foo; //or meh;
end.


However, beware and be careful of the potential stack overflow if each function never returns and cyclical redundancies. Just make sure you know what you're doing and when to call each. As long as it doesn't call each-other infinitely like my example above, you'll be fine.


Another option is to use function pointers which do not require forwarding (it however does have the same warnings as the above).. This one is going to look a bit tricky or confusing at first but meh:


procedure Foo(Func: Procedure(F: Procedure));
begin
writeln('Foo called');
Func(@Foo);
end;

Procedure Meh(Func: Procedure(F: Procedure));
begin
writeln('Meh called');
Func(@Meh);
end;

begin
Foo(@Meh); //Or Meh(@Foo);
end;

Frement

2014-02-27 14:17:45

Example how you can fix this:
program new;

procedure Proc2; forward;

procedure Proc1;
begin
Writeln('1');
end;

procedure Test;
begin
Proc1;
Proc2;
end;

procedure Proc2;
begin
Writeln('2');
end;

begin
Test;
end.

Twinki

2014-02-27 14:27:22

Ahh Thanks :)